MySQL 数据库中的数据未更新。有什么想法吗?
我正在尝试使用以下内容来更新 MySQL 数据库。我连接正常,提交更改时没有收到任何错误,但数据库没有显示任何更改。有什么想法吗?
<?php
//replace usernaem,password, and yourdb with the information for your database
mysql_connect("######","######","######") or die("Error: ".mysqlerror());
mysql_select_db("#####");
//get the variables transmitted from the form
$id = $_POST['id'];
$trailName = $_POST['trailName'];
$trailDesc = $_POST['trailDesc'];
$trailHike = $_POST['trailHike'];
$trailBike = $_POST['trailBike'];
// update data in mysql database
$sql="UPDATE markers SET trailName='$trailName', trailDesc='$trailDesc', trailHike='$trailHike' WHERE id='$id'";
mysql_query($sql) or die ("Error: ".mysql_error());
echo "Database updated. <a href='edit.php'>Return to edit info</a>";
?>
I am trying to use the below to update a MySQL DB. I connect fine and get no errors when submitting a change yet the DB is not showing any changes. Any thoughts?
<?php
//replace usernaem,password, and yourdb with the information for your database
mysql_connect("######","######","######") or die("Error: ".mysqlerror());
mysql_select_db("#####");
//get the variables transmitted from the form
$id = $_POST['id'];
$trailName = $_POST['trailName'];
$trailDesc = $_POST['trailDesc'];
$trailHike = $_POST['trailHike'];
$trailBike = $_POST['trailBike'];
// update data in mysql database
$sql="UPDATE markers SET trailName='$trailName', trailDesc='$trailDesc', trailHike='$trailHike' WHERE id='$id'";
mysql_query($sql) or die ("Error: ".mysql_error());
echo "Database updated. <a href='edit.php'>Return to edit info</a>";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是因为 update 语句中的 where 子句没有找到您传递给它的 id。
It is probably because the where clause in the update statement is not finding the id you are passing it.
查询有问题。您的查询应该是这样的..
UPDATE 标记 SET TrailName='".$trailName."', TrailDesc='".$trailDesc."', TrailHike='".$trailHike."' WHERE id='$id '
There is a problem in query. your query suppose to be like this..
UPDATE markers SET trailName='".$trailName."', trailDesc='".$trailDesc."', trailHike='".$trailHike."' WHERE id='$id'
我同意 OscarMk 的观点:可能找不到 id。为什么要在更新查询中引用 id 值? ID 通常是 INT,并且不应加引号。
I agree with OscarMk: the id is probably not being found. Why are you quoting the id value in the update query? IDs are usually INTs, and should not be quoted.