View unanswered posts | View active topics It is currently Mon May 23, 2022 10:18 pm



Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
 Inserting a foreign key 
Author Message
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Thanks Xnuiem for helping me to clear my issues. :):)


Mon Nov 16, 2009 11:18 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Hi Xnuiem, sorry to trouble once again.

after completing the earlier issue, i was wondering if the same method of the code can be used if i am do update the data?

i.e. after retrieving from the database into a form i created, allow user to edit on the form and update the database.

Code:
list($C_insert) = mysql_fetch_row(mysql_query("select C_id
      from C where C_label = '$devC' limit 1"));

list($B_insert) = mysql_fetch_row(mysql_query("select B_id
      from B where B_type = '$devB' limit 1"));

list($D_insert) = mysql_fetch_row(mysql_query("select D_id
      from D where D_model = '$devD' limit 1"));


list($E_insert) = mysql_fetch_row(mysql_query("select E_id from E where E_num = '$val_E_num' and E_type = '$val_E_type'
       and E_partno = 'val_E_partno' $ limit 1"));
if ($E_insert == '')
{
$E_insert = "INSERT INTO E (E_num, E_type, E_partno)
  VALUES ('$val_E_num', '$val_E_type', '$val_E_partno' )";
$result = mysql_query($E_insert) or die (mysql_error());
$E_insert = mysql_insert_id() or die (mysql_error());   
}


list($S_insert) = mysql_fetch_row(mysql_query("select S_id from S where S_site = '$val_S_site' and S_name = '$val_S_name' limit 1"));
if ($S_insert == '')
{
$S_insert = "INSERT INTO S (S_site, S_name)
  VALUES ('$val_S_site', '$val_S_name')";
$result = mysql_query($S_insert) or die (mysql_error());
$S_insert = mysql_insert_id() or die (mysql_error());   
}


  $sql = "UPDATE dev
    SET dev_num = '$devnum',
    dev_C = '$C_insert',
    dev_B = '$B_insert',
    dev_D= '$D_insert',
    dev_E = '$E_insert',
    dev_S = '$S_insert',
    dev_dibid = '$val_dib',
    dev_remark = '$val_remark'
    WHERE
    dev_id = '$getid'
    LIMIT 1 "; 
    mysql_query($sql) or die ("ERROR!" .mysql_error());
     


Tue Nov 17, 2009 7:28 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Hi Xnuiem,

I managed to solve the problem after a few more tries and it's work with the code i posted earlier on. Sorry for the inconveniences..

cheers :)


Tue Nov 17, 2009 10:26 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.