sleazyfish Posted October 29, 2010 Share Posted October 29, 2010 Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance Link to comment https://forums.phpfreaks.com/topic/217188-table-field-is-equal-to-another-tables-id-field/ Share on other sites More sharing options...
revraz Posted October 29, 2010 Share Posted October 29, 2010 Start writing some code to write the values to a DB, then ask questions on the parts you don't understand. Link to comment https://forums.phpfreaks.com/topic/217188-table-field-is-equal-to-another-tables-id-field/#findComment-1127950 Share on other sites More sharing options...
sleazyfish Posted October 29, 2010 Author Share Posted October 29, 2010 ok..sorry i didn't really give you much to go on.. how about this: how can i convert this script to include 2 insert queries into different tables such as: INSERT INTO cards(col2, col3, ....) VALUES('col2_value,'col3_value',...); INSERT INTO jingle (card_id) VALUES (LAST_INSERT_ID()); <? // fill with correct data for your server configuration $server = "localhost"; $username = "*******"; $password = "*******"; $database = "*******"; if (!mysql_connect($server, $username, $password)) { $r_string = '&errorcode=1&'; } elseif (!mysql_select_db($database)) { $r_string = '&errorcode=2&'; } else { $ins_str = "INSERT INTO jingle VALUES (NULL, '".addslashes($_GET['from'])."', '".$_GET['dateposted']."', '".$_GET['score']."')"; if (!mysql_query ($ins_str)) { $msg = mysql_error(); $r_string = '&errorcode=3&msg='.$msg; } else { // pass back id of inserted record $id = mysql_insert_id(); $r_string = '&errorcode=0&id='.$id.'&'; } } echo $r_string; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/217188-table-field-is-equal-to-another-tables-id-field/#findComment-1127953 Share on other sites More sharing options...
revraz Posted October 29, 2010 Share Posted October 29, 2010 Did you try it with 2 queries as in your question? Link to comment https://forums.phpfreaks.com/topic/217188-table-field-is-equal-to-another-tables-id-field/#findComment-1127979 Share on other sites More sharing options...
sleazyfish Posted October 29, 2010 Author Share Posted October 29, 2010 hi, I tried: } else { $ins_str = "INSERT INTO cards VALUES (NULL, '".addslashes($_GET['k1'])."','".$_GET['k2']."','".$_GET['k3']."',)"; $id = mysql_insert_id(); $ins_str = "INSERT INTO jingle VALUES (NULL, '".addslashes($_GET['sender'])."', '".$_GET['recipient']."', '".$_GET['password']."', '".$_GET['date']."', arrangement='&id' )"; but this only inserts into jingle not card and returns '1' in the arrangement field:confused: Link to comment https://forums.phpfreaks.com/topic/217188-table-field-is-equal-to-another-tables-id-field/#findComment-1127993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.