will_1990 Posted March 4, 2009 Share Posted March 4, 2009 Hi, I manged to sort a query error earlier and using the advice i was given earlier i used this method to perform a select then edit query however it does not work. Is there a way to combine the two queries or make them work togeather. I want to select a row and then edit the date destoryed here is the code: //connect to the database //database information $host = "stocks"; // Host name $username = "njpeddle"; // Mysql username $password = "mysql5"; // Mysql password $db_name = "njpeddle"; // Database name $db_table = "Staff"; //connecting to the staff table mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //query $q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = $bcid and BtId =$btid"); $res1 = mysql_query($q1) or die (mysql_error()); if ($res1){ $q2 = ("INSERT INTO BookCopy (DateDestroyed) VALUES ('$dd')"); $res2 = mysql_query($q2) or die (mysql_error()); } if ($res2) { //If it ran ok. // Print message below: echo '<h4> Confirmation that the book been removed from the library Database.</h4>'; there is more but i dont think its needed! great thanks alot for any advice pointing me in the right direction! Link to comment https://forums.phpfreaks.com/topic/147852-a-2-part-query-error/ Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 $q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = $bcid and BtId =$btid"); You should quote the values for mysql $q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = '$bcid' AND BtId = '$btid'"); also, the way you set up the query, if it fails it will die, therefore there is no need for the if statement, thats just a point out. secondly, you can't INSERT a change, you do UPDATE Link to comment https://forums.phpfreaks.com/topic/147852-a-2-part-query-error/#findComment-776039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.