开发者

Data in a MySQL Database is not being updated. Any thoughts?

开发者 https://www.devze.com 2023-03-16 17:15 出处:网络
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?

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_d开发者_JAVA百科b("#####");

//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>";
?>


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


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'


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消