普通网友 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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵