zed420 Posted November 3, 2008 Share Posted November 3, 2008 Hi ALL Can anyone help me on this query please, all I'm trying to do is Update three tables in a same query. if($_POST['submit']) { foreach($_POST as $job_id) { mysql_query("UPDATE job_tb,blockbook,blockbook2 SET job_tb.cust_address = 'Cancel' blockbook.cust_address = 'Cancel' blockbook2.cust_address1 = 'Cancel' WHERE job_tb.job_id = '$job_id' AND blockbook.job_id = '$job_id' AND blockbook2.job_id = '$job_id'"); if (mysql_affected_rows() > 0) { // execute query print "<font color=red size=2> No. = $job_id has been Updated</font><p>"; } } } Thanks Zed Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/ Share on other sites More sharing options...
genericnumber1 Posted November 3, 2008 Share Posted November 3, 2008 do mysql_query("blah blah") or die(mysql_error()); I can see some problems with your query, but so can mysql_error()! Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/#findComment-680896 Share on other sites More sharing options...
zed420 Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks for replying but Where am I going wrong??? it no different than 2nd line so why error there and not in 2nd line? You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'blockbook.cust_address = 'Cancel' blockbook2.cust_address1 = 'Cancel' W' at line 3 Anyone any suggestions please. Thanks Zed Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/#findComment-680995 Share on other sites More sharing options...
Adam Posted November 3, 2008 Share Posted November 3, 2008 job_tb.cust_address = 'Cancel', blockbook.cust_address = 'Cancel', ... .. need commas! Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/#findComment-681003 Share on other sites More sharing options...
zed420 Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks that has got rid of my error message but it still not Updating every time I press submit button it takes off the background color that I'm using. Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/#findComment-681023 Share on other sites More sharing options...
Adam Posted November 3, 2008 Share Posted November 3, 2008 foreach($_POST as $job_id) { isn't the best way of looping through the jobs, with that $_POST['submit'] is also goin to be queried - with or without success. How are you sending the 'job_ids' to the script? Assuming there's a matching job id in each of the three tables it should work. It's either a problem with your logic or the inputs.. And I can't see enough code to say anything about the background colour problem.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/131132-problem-with-update/#findComment-681029 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.