Jump to content

please check n suggest my UPDATE code


coolagniho

Recommended Posts

how to update the record of one table in which condition is that the it should similar to the other table feild only. e.g field of table1 will update only when the feild1 of table1 is equal to field2 of table2 in php??

while im using following command

 

mysql_select_db("db1",$con);
$query = "SELECT table2.feild1 , table2.feild1 " .
"FROM table2, table1 " .
"WHERE table1.feild2 = table2.feild1 ";

$data = mysql_query($query) 
or die(mysql_error()); 

$sql="UPDATE table2 SET feild2='$_POST[value2]', feild3='$_POST[value3]' WHERE table1.feild2 = $data "; 

Link to comment
Share on other sites

Your description is a little too general to really provide a good example, but here is an example (only need ONE query)

 

$field2value = mysql_real_escape_string(trim($_POST['value2']));
$field3value = mysql_real_escape_string(trim($_POST['value3']));

$query = "UPDATE table2
          SET field2='{$field2value}',
              feild3='{$field3value}'
          WHERE table2.field1 IN (SELECT field2 FROM table1)";

 

This is just an example. May need to modify the sub-query

Link to comment
Share on other sites

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.