首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP变量在第二页上未正确返回

PHP变量在第二页上未正确返回
EN

Stack Overflow用户
提问于 2018-08-16 23:51:17
回答 2查看 63关注 0票数 0

所以我有一个超文本标记语言页面(在它上面加载了一个functions.php和一个header.php页面),在post时,它成功地执行了位于functions.php页面上的一个函数。我试图在post后将一个值返回给functions.php页面,该值将指示成功或错误,但我需要将其显示在某个div中,否则我只会让html页面回显结果。我不喜欢使用ajax,但如果有必要,我会这样做。

编辑:对不起,忘记解释发生了什么。是啊。因此,在post之后,它同时显示成功和错误消息,就像同时返回两个if语句一样。它将显示“已成功更新!”和“错误!”在同一时间。

第1页(html页):

include('session.php');
include('header.php'); // Includes Header Script
include('functions.php');

$cus_details=getAddress($login_id);

foreach($cus_details as $cus_details) {
}

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   $result = updateAddress($login_id, $_POST);
}
?>
<body style="background-image: url('Scripts/background.png'); -moz-background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-size: cover;">
<center><div id="signup">
<div class="container1">
<form class="addressForm" action="" method="post">
<?php if ( $result == true ) { ?>
    <br><br><center><span4>Updated Successfully!</span4></center>
<? } else if ( $result == false ) { ?>
    <br><br><center><span4>Error!</span4></center>
<?php } ?>
..... (more html)

第2页(函数页):

// Update Customer Address
function updateAddress($login_id, $data) {
    // Establishing Connection with Server by passing server_name, user_id and password as a parameter
    $connection = mysqli_connect("localhost", "root", "");
    // Selecting Database
    $db = mysqli_select_db($connection,"db_name");
    // SQL Query To Fetch Complete Information Of User
    $ses_sql=("update rma_customer_address set cus_address_1='".$data['address1']."' WHERE cus_id='$login_id' AND cus_address_type=0");
    if (mysqli_query($connection, $ses_sql)) {
        $success = true;
    } else {
        $success = false;
    }
    mysqli_close($connection);
    return $success;
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51880976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档