Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.