普通网友 2018-08-16 15:51
浏览 35
已采纳

PHP变量在第二页上没有正确返回

So I have an HTML page (has some PHP on it loading a functions.php and a header.php page) and upon post, it executes a function that is located on functions.php page successfully. I am trying to return a value back to the html page after post that would indicate a success or error but I need it to be displayed within a certain div, otherwise I would just let the functions.php page echo the result. I'd prefer not to use ajax but if I have to then I will.

EDIT: Sorry, forgot to explain what is happening. Duh. So after post, it shows both the success and the error message, as if both if statements are being returned at the same time. It will show "Updated Successfully!" AND "Error!" at the same time.

Page 1 (html page):

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)

Page 2 (functions page):

// 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;
}
  • 写回答

2条回答 默认 最新

  • douyi2798 2018-08-16 20:04
    关注

    I am posting @William_Wilson's comment as the answer as it was user error on my part which he saw. Does your server support short tags, because you're using them <? instead of <?php in the middle of your if/elseif which could be causing your issues

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器