我正在尝试创建一个系统,当我提交表单时,在页面刷新后它应该显示我从数据库中获取的新值。当它们进入数据库时,这些值很有效,但是只有当我再次刷新时它们才会在提交之后显示。谢谢你的帮助
<?php
include("connect.php");
$query = "SELECT * FROM `laliga`";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$id = $row['id'];
$home = $row['home'];
$away = $row['away'];
$win = $row['win'];
$draw = $row['draw'];
$lose = $row['lose'];
}
echo "<h2>La Liga</h2>";
echo $home, " - ", $away;
if (isset($_POST) && $_POST['laliga'] == 1){
$select = mysql_real_escape_string($_POST['laliga']);
$select = $win + $select;
mysql_query("UPDATE laliga SET win='$select'");
}else if (isset($_POST) && $_POST['laliga'] == 'X'){
$select = mysql_real_escape_string($_POST['laliga']);
$select = '1';
$select = $draw + $select;
mysql_query("UPDATE laliga SET draw='$select'");
}else if (isset($_POST) && $_POST['laliga'] == 2){
$select = mysql_real_escape_string($_POST['laliga']);
$select = '1';
$select = $lose + $select;
mysql_query("UPDATE laliga SET lose='$select'");
}
header('Location: ../laliga.php');
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="laliga" value="1">1
<input type="radio" name="laliga" value="X">X
<input type="radio" name="laliga" value="2">2
<input type="submit" name="submit" value="Submit"/>
</form>
<br/>
<?php
echo $home, " -> ", $win;
echo "<br/>Barazim -> ", $draw,"<br/>";
echo $away, " -> ", $lose;
?>
答案 0 :(得分:1)
你应该处理PHP文件顶部的所有帖子数据,而标题函数将解决你的问题,这是一种愚蠢而低效的方式来接近它。通过处理发布数据并首先更新数据库,当您查询数据库时数据就在那里!此时您正在尝试查找数据然后添加它。这有意义吗? 祝你好运!
答案 1 :(得分:0)
添加:
header('Location: <mypage.php>');
mysql_query
之后。