tofeks Posted April 19, 2007 Share Posted April 19, 2007 HI Im new for php and my sql. i have an update script. update user data to mysql. when i run the script it did'nt give any error and shows sucessfully updated but when i check the database it not updated. please check my script and help me on this matter. my script is: [root@www uniform]# less update_ac.php <?php $host="localhost"; // Host name $username="rmsasi"; // Mysql username $password="thaufek"; // Mysql password $db_name="uniform"; // Database name $tbl_name="uniform"; // Table name $id=$_POST['id']; $Uniform_Type=$_POST['Uniform_Type']; $quantity=$_POST['quantity']; // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET Uniform_Type='$Uniform_Type', quantity='$quantity', update_time=NOW() WHERE 'id'='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo " $quantity,$Uniform_Type,$id Successfully uppdate on $tbl_name database"; echo "<BR>"; echo "<a href='select.php'>View result</a>"; } else { echo "ERROR:".mysql_error(). "<BR>"; } ?> Link to comment https://forums.phpfreaks.com/topic/47698-solved-need-help/ Share on other sites More sharing options...
flappy_warbucks Posted April 19, 2007 Share Posted April 19, 2007 Personally i wouldn't put variables in literal quotes i.e. ur using ' instead of " but that aside, lets get back to the problem at hand. i was looking at your SQL when i saw this: $sql="UPDATE $tbl_name SET Uniform_Type='$Uniform_Type', quantity='$quantity', update_time=NOW() WHERE 'id'='$id'"; Now... you appear to have put your condition inside quotes... i am not sure you can do that. Moving on from there, what i would do is this: $sql="UPDATE $tbl_name SET Uniform_Type=\"". $Uniform_Type. "\", quantity="\". $quantity. "\", update_time=". NOW(). " WHERE id="\". $id. "\""; and see if that would solve the problem Link to comment https://forums.phpfreaks.com/topic/47698-solved-need-help/#findComment-232931 Share on other sites More sharing options...
tofeks Posted April 19, 2007 Author Share Posted April 19, 2007 hi actually this sript is working $sql="UPDATE $tbl_name SET Uniform_Type='$Uniform_Type', quantity='$quantity', update_time=NOW() WHERE id='$id'"; Link to comment https://forums.phpfreaks.com/topic/47698-solved-need-help/#findComment-232999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.