所以我有一个超文本标记语言页面(在它上面加载了一个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;
}
https://stackoverflow.com/questions/51880976
复制相似问题