【发布时间】:2016-12-01 19:39:15
【问题描述】:
我的问题是在php 页面中提交表单元素后,页面没有刷新。这是我的代码。
<?php
session_start();
include('db.php');
include('pages.php');
?>
表单元素
<form action = "<?php echo $_SERVER['PHP_SELF'];?>" method = "POST">
<table style="width:70%">
<tr>
<td width="10%">First Name</td>
<td width="20%"><input style="border-radius: 4px; border: 2px solid gray; height: 20px; width: 180px;" type="text" name="fname" value="<?php echo $f_name;?>"></td>
</tr>
<input style="border-radius: 5px; width: 100px; height: 25px;" type="submit" name="account_update" value="Update"/></td>
</table>
</form>
if(isset($_POST['account_update']) && $_POST['account_update'] == 'Update'){
$fname_edit = $_POST['fname'];
$sql = $db->prepare("SELECT * from table where email = ?");
$sql->bind_param("s",$email);
$sql->execute();
$sql = $sql->get_result();
if(($getRowCount = $sql->num_rows) == 1){
$updateQuery = $db->prepare("UPDATE info set first_name=? where email = ?");
$updateQuery->bind_param("ss",$fname_edit,$email);
$updateQuery->execute();
}
}
?>
所以点击更新,将数据插入到故事中,但它只在我第二次刷新时才显示在页面上。
还有。 pages.php 是通过包含获取的另一个页面。如果我删除include('pages.php'),我的当前页面会很好地刷新,但不是用它。关于如何把这个东西拿出来的任何建议都会有很大帮助。
【问题讨论】:
-
我没有看到任何有关重定向的相关代码。你很有可能在标题之前输出。
-
这是在哪里定义的?
$email。我看到的只是$fname_edit,没有任何东西可以支持$_POST['fname']数组。 -
if(isset(...之前好像少了<?php -
检查您是否在标头之前输出错误报告php.net/manual/en/function.error-reporting.php 或其他内容,如果您失败了。您需要在成功查询后放置重定向代码,并且不知道您在哪里使用它。
-
也许我说的不对,但是你用 JS 刷新,而不是用 PHP