Jump to content

Inserting into multiple tables


omesa

Recommended Posts

Hello guys,
I have a problem with the code below. The script is meant to insert the values collected from a form and be inserted into two tables namely the client table(main) and a clientchild table(child) repectively.
The members's values are inserted well but the problem is that the clientchild's values aren't added, but when I interchange the codes, they are added to the child table and vis a vis.
any help will be appreciated.
thank you in advance.

here's the code

<html>
<head>
<title>insert</title>
</head>
<body>
<?php

global $Names,$Kounta;

$new_name = addslashes('$Names');
$new_kounta = addslashes('$Kounta');

$conn = mysql_connect("localhost", "root", "")or die("Can't connect");
mysql_select_db("myndb",$conn) or die("Can't select!");

//insert into main client table
$squery = "insert into client(id,Names) values('NULL', '$Names')";
$result = mysql_query($squery, $conn);


if(isset($id))
{
  //get user id
  $user_id = mysql_insert_id($conn);
 
  //insert into clientchild table
  $squery = "insert into clientchild values('$Kounta', $user_id)";
  $result = mysql_query($squery,$conn);

}

?>
</body>
</html>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.