我正在尝试使用您从下拉菜单中选择的内容更新我的表格,然后将文本放入文本框中,它将更新特定列(fixture_result)。输出告诉我它已更新但是当我查看数据库时它没有完成它。
我不知道此问题是否曾被提出过。我查看了一些与更新有关的表格,但没有多大帮助;但如果你看到我做错了什么我会很感激。
<html>
<head>
<title>The Score</title>
</head>
<body>
<form id="form1" name="form1" method="post">
Fixture:
<select name='NEW'>
<option value="">--- Select ---</option> <br>
<?php
if(isset($db_name)&&$db_name!=""){
$select=$_POST['NEW'];
}
?>
<?php
$list=mysql_query("select * from Fixture_Information order by fixture_id asc");
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<?php echo $row_list['fixture_id']; ?>">
<?php if($row_list['fixture_id']==$select){ echo "selected"; } ?>
<?php echo $row_list['fixture_name']; ?>
</option>
<?php
}
?>
Input Score: <input type="text" name="myusername">
<input type="submit" value="Submit">
<?php
$data =$_POST['myusername'];
$select=$_POST['NEW'];
$sql=("UPDATE Fixture_Information
set fixture_result = '$data'
where fixture_name = '$select'");
$checkresult = mysql_query($sql);
if ($checkresult) echo 'update query succeeded';
else echo 'update query failed';
mysql_close();
?>
</select>
</form>
</body>
</html>
答案 0 :(得分:2)
您只检查更新语句的成功,在您的情况下为true
。但是,您不检查更新的行数。您可以将mysql_affected_rows
用于此
if (mysql_affected_rows() > 0)
echo 'update query succeeded';
else
echo 'update query failed';