MYSQL / php basic question -


i want see if specified value there in table t1 . , if value exists want enter value's in table t2,

how can in php ?

i want check existence insert values following command

i want in format

if ( table1.id = exist's )    {insert  table2 ( values ) } 

what proper way write code php?

well, might you.

updated answer

well, table tb1

+-------+-------------+------+-----+---------+-------+ | field | type        | null | key | default | | +-------+-------------+------+-----+---------+-------+ | fld1  | varchar(20) | yes  |     | null    |       | | fld2  | varchar(20) | yes  |     | null    |       | | fld3  | varchar(20) | yes  |     | null    |       | +-------+-------------+------+-----+---------+-------+ 

and table tb2

+-------+-------------+------+-----+---------+-------+ | field | type        | null | key | default | | +-------+-------------+------+-----+---------+-------+ | fld1  | varchar(20) | yes  |     | null    |       | | fld2  | varchar(20) | yes  |     | null    |       | | fld3  | varchar(20) | yes  |     | null    |       | +-------+-------------+------+-----+---------+-------+  insert tb1 (fld1, fld2, fld3) select tb2.fld1, tb2.fld2,      tb2.fld3 tb2;   

works version 5.1.49, the answer be

$sql = "insert table1 (fld1, fld2, fld3) select table2.fld1, ".     table2.fld2, table2.fld3 table2 table2.id= ".$somevalue; 

update don't need check id, automatically check, if there no id then, u append null

insert table2 (fld1, fld2, fld3) select table1.fld1, table1.fld2, table1.fld3  table1 table1.id = someid ; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -