php - SQL insert and update in the same time -



php - SQL insert and update in the same time -

hey have query insert table new info , want in same time update outher table id of new info have entered. ex:

mysql_query("insert `test` (`name`) values ('mark')"); $query = mysql_query("select `id` `test` `name` = 'mark'"); $id = mysql_result($query,0); mysql_quey("update `test2` set `test_id` = $id `name` = 'mark'");

how do @ same time? because doing way insert new info , dont update other.

cumps.

try :

mysql_query("insert `test` (`name`) values ('mark')"); $id = mysql_insert_id(); mysql_quey("update `test2` set `test_id` = $id `name` = 'mark'");

i've changed backticks single quotes in first insert values, backticks should never used field values.

also i've changed utilize 2 queries, mysql_insert_id() lastly inserted id without needing query it.

ref : http://www.php.net/manual/en/function.mysql-insert-id.php

php mysql sql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -