gergy008 Posted September 6, 2009 Share Posted September 6, 2009 Hi, I need to run two different queries... Here is my Query: INSERT INTO banning (`user`, `type`, `until`, `note`) VALUES ('$user', '$bantype', '$stamp', '$note'); UPDATE `users` SET `banned`='1' WHERE `login`='$user'; But it doesn't work... It dies as: 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 'UPDATE `users` SET `banned`='1' WHERE `login`='--User--'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/173342-multiple-queries-to-save-server-resources/ Share on other sites More sharing options...
Mark Baker Posted September 6, 2009 Share Posted September 6, 2009 Hi, I need to run two different queries... Run as two single queries: $sql = "INSERT INTO banning (`user`, `type`, `until`, `note`) VALUES ('$user', '$bantype', '$stamp', '$note')"; $result = mysql_query($sql); $sql="UPDATE `users` SET `banned`='1' WHERE `login`='$user'"; $result = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/173342-multiple-queries-to-save-server-resources/#findComment-913722 Share on other sites More sharing options...
Alex Posted September 6, 2009 Share Posted September 6, 2009 $q1 = "INSERT INTO banning (`user`, `type`, `until`, `note`) VALUES ('$user', '$bantype', '$stamp', '$note')"; $q2 = "UPDATE `users` SET `banned`='1' WHERE `login`='$user'"; mysql_query($q1); mysql_query($q2); Quote Link to comment https://forums.phpfreaks.com/topic/173342-multiple-queries-to-save-server-resources/#findComment-913723 Share on other sites More sharing options...
gergy008 Posted September 6, 2009 Author Share Posted September 6, 2009 Hi, I need to run two different queries... Run as two single queries: $sql = "INSERT INTO banning (`user`, `type`, `until`, `note`) VALUES ('$user', '$bantype', '$stamp', '$note')"; $result = mysql_query($sql); $sql="UPDATE `users` SET `banned`='1' WHERE `login`='$user'"; $result = mysql_query($sql); So you can't migrate 2 different queries and run it as a single query? Quote Link to comment https://forums.phpfreaks.com/topic/173342-multiple-queries-to-save-server-resources/#findComment-913725 Share on other sites More sharing options...
Mark Baker Posted September 6, 2009 Share Posted September 6, 2009 So you can't migrate 2 different queries and run it as a single query?No, it's a protection against sql injection If you run as two separate queries, it'll be easier for you to identify any problems, and easier to maintain... especially if you have proper error trapping. You can execute multiple queries with mysqli Quote Link to comment https://forums.phpfreaks.com/topic/173342-multiple-queries-to-save-server-resources/#findComment-913727 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.