Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP -
i have 2 tables, named shows , show_connections. ask user put in tv show names via post , values show1connection , show2connection. query separately defined function takes input , puts in sql.
i have following code:
$show1_name = $_post["show1connection"]; $show2_name = $_post["show2connection"]; $fail = query ("insert show_connections (show1_id) select id shows name = '$show1name'"); $fail2 = query ("insert show_connections (show2_id) select id shows name = '$show2name'"); my main problem want set show1_id , show2_id proper ids in 1 row. right now, syntax (which closest i've come solving problem) set show1_id id of show 1 , show2_id id of show 2, end on 2 separate rows. how make sure appear in same row?
try -
insert show_connections (show1_id, show2_id) select s1.id, s2.id shows s1, shows s2 s1.name = '$show1name' , s2.name = '$show2name'" side note - make sure sanitize user data - $show1name/$show2name. better update code mysqli_ or pdo , use prepared statements.
Comments
Post a Comment