MySQL数据库中的数据未更新。有什么想法吗?

时间:2022-04-16 17:30:12

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?

我正在尝试使用以下内容来更新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>";
?>

3 个解决方案

#1


2  

It is probably because the where clause in the update statement is not finding the id you are passing it.

这可能是因为update语句中的where子句没有找到传递它的id。

#2


0  

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'

UPDATE markers SET trailName ='“。$ trailName。”',trailDesc ='“。$ trailDesc。”',trailHike ='“。$ trailHike。”'WHERE id ='$ id'

#3


0  

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.

我同意OscarMk:可能没有找到id。为什么在更新查询中引用id值? ID通常是INT,不应引用。

#1


2  

It is probably because the where clause in the update statement is not finding the id you are passing it.

这可能是因为update语句中的where子句没有找到传递它的id。

#2


0  

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'

UPDATE markers SET trailName ='“。$ trailName。”',trailDesc ='“。$ trailDesc。”',trailHike ='“。$ trailHike。”'WHERE id ='$ id'

#3


0  

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.

我同意OscarMk:可能没有找到id。为什么在更新查询中引用id值? ID通常是INT,不应引用。