coolagniho Posted September 27, 2011 Share Posted September 27, 2011 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 "; Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 27, 2011 Share Posted September 27, 2011 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 Quote Link to comment 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.