普通网友 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 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐