Jump to content

Mysql query not working.. php problem


Lamez

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/140643-mysql-query-not-working-php-problem/
Share on other sites

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.

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.