Jump to content

table field is equal to another tables ID field


sleazyfish

Recommended Posts

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

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

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:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.