Q:

Insert data to different tables

<td>
    <label id="" class="" for="">Surname/Last Name
        <span class="required">*</span>
    </label>
</td> 
<input type="text" id="" name="lname" size="20" required value="" class=" " aria-required="true" />
<td>
    <label id="" class="" for="">Agency
        <span class="required">*</span>
    </label>
</td>
<td>
    <input type="text" id="agency" name="agency" size="30" required value="" class=" " aria-required="true" />              </td>
<td>
    <label id="" class="" for="">Organizer
        <span class="required">*</span>
    </label>
</td>
<td>
    <input type="text" id="trorganizer" name="trorganizer" size="30" required value="" class=" " aria-required="true" />
</td>

 //my php code here
 $lname=strtoupper($_POST['lname']);
 $agency=strtoupper($_POST['agency']);
 $trorganizer=strtoupper($_POST['trorganizer']);

 $sql1 = "INSERT INTO personalinfo (lname) VALUES ('$lname')"; 
 $sql2 = "INSERT INTO pep (agency) VALUES ('$agency')"; 
 $sql3 = "INSERT INTO training (trorganizer) VALUES ('$trorganizer')";

//I think I have a problem with my sql code
     mysql_select_db('DATABASENAME');       
     $retval = mysql_query( $sql, $conn );          
     if(! $retval )             
     {
        die('Could not enter data: ' . mysql_error());
     } 

     echo "Data added successfully!";
     mysql_close($conn);            
   }    
}

Anyone can help me how to insert data into different tables? I can't save these data. Thanks for your help. It'll much appreciated!
Thanks!

A:

This may help you:
<form action='your_script_name.php' method='post'>
<table>
<tr>
<td>
<label id="" class="" for="">Surname/Last Name
<span class="required">*</span>
</label>
</td> 
<input type="text" id="" name="lname" size="20" required value="" class=" " aria-required="true" />
<td>
<label id="" class="" for="">Agency
<span class="required">*</span>
</label>
</td>
<td>
<input type="text" id="agency" name="agency" size="30" required value="" class=" " aria-required="true" />
</td>
<td>
<label id="" class="" for="">Organizer
<span class="required">*</span>
</label>
</td>
<td>
<input type="text" id="trorganizer" name="trorganizer" size="30" required value="" class=" " aria-required="true" />
</td>
<td>
<input type="submit" value='Submit' name='submit'/>
</td>
</tr>
</table>
</form>

You PHP script:
$lname=strtoupper($_POST['lname']);
$agency=strtoupper($_POST['agency']);
$trorganizer=strtoupper($_POST['trorganizer']);

$db_con = mysql_connect('localhost', 'database_user_name', 'database_password');
if (!$db_con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('database_name', $db_con) or die('Could not select database.');

$sql1 = "INSERT INTO `personalinfo` (`lname`) VALUES ('$lname')"; 
$sql2 = "INSERT INTO `pep` (`agency`) VALUES ('$agency')"; 
$sql3 = "INSERT INTO `training` (`trorganizer`) VALUES ('$trorganizer')";

// command to execute query
$retval = mysql_query($sql1);          
if(!$retval ) {
    die('Could not enter data: ' . mysql_error());
}
$retval = mysql_query($sql2);          
if(!$retval ) {
    die('Could not enter data: ' . mysql_error());
}
$retval = mysql_query($sql3);          
if(!$retval ) {
    die('Could not enter data: ' . mysql_error());
}

echo "Data added successfully!";
mysql_close($conn);            

Hope this may help you.

