Lamez Posted January 13, 2009 Share Posted January 13, 2009 I am trying to get my insert query to insert a 1 in the accept field, but it is add a 0 instead. Here is the code: <?php $me_id = findInfo($user_, "id"); $them_id = findInfo($a_usr, "id"); mysql_query("UPDATE `friends` WHERE `friend_id` = '".$them_id."' AND `user_id` = '".me_id."' SET `accept` = '1'"); mysql_query("INSERT INTO `friends` (user_id, friend_id, accept) VALUES('$me_id', '$them_id', '1')")or die(mysql_error()); echo "<b>".$a_usr."</b> has been added as your friend!"; ?> no errors are being returned. The update query works, but not the insert! Quote Link to comment https://forums.phpfreaks.com/topic/140643-mysql-query-not-working-php-problem/ Share on other sites More sharing options...
uniflare Posted January 13, 2009 Share Posted January 13, 2009 are you sure that update works? you have an error in the update query, me_id should be $me_id. the insert should not work if the update works unless you dont have any unique fields (like the user_id field), you seem to be trying to insert a copy of the row you just updated. Why would you want to do this? can you explain this "Add Friend" code with a little explanation of the mysql tables involved, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/140643-mysql-query-not-working-php-problem/#findComment-736018 Share on other sites More sharing options...
cwarn23 Posted January 13, 2009 Share Posted January 13, 2009 Although that type of mysql insert query is common I prefer to use the set element. So try the following: mysql_query("INSERT INTO `friends` SET `user_id`='".$me_id."', `friend_id`='".$them_id."', `accept`='1'") or die(mysql_error()); Anyway that is the way I prefer to do it. Quote Link to comment https://forums.phpfreaks.com/topic/140643-mysql-query-not-working-php-problem/#findComment-736019 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.