我在更新表单中看不到问题,但无论我做什么,它都不会更新我的数据库。 我希望这里有人能帮助我。
我尝试在更新语句后使用mysql_error(),但没有发现错误,并尝试回显更新语句,但没有发现任何问题。
网址 = http://localhost/maga/php/update_red.php?id=6&read=14
<?php
$host="localhost";
$pass="*****";
$user="my_db_user";
$db="my_db_name";
$tblname="artikler";
$con=mysql_connect($host, $user, $pass)or die(mysql_error());
mysql_select_db($db)or die(mysql_error());
$read=(int)$_GET['read'];
$id=$_GET['id'];
$read++;
mysql_query("UPDATE $tblname SET read='$read' WHERE id='$id'");
?>
最佳答案
read
是 reserved word,因此需要特别用反引号引起来才能在查询中工作
所以尝试一下
if (!mysql_query("UPDATE $tblname SET `read`='$read' WHERE id='$id'"))
{
die("update failed with error ".mysql_error());
}
此外,$id 值没有以任何方式进行清理,因此代码很容易受到 SQL 注入(inject)攻击。绝对值得你花时间学习这些东西。
关于php - MySQL 不会用 php 更新数据库数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9672241/