if(isset($_POST['submit'])){// handle the form
// Connect to the database.
require_once ('incl/mysql_connect.php');
// Check for a screen name.
if (eregi ("^[[:alnum:]_]{4,50}$", stripslashes(trim($_POST['user_sn'])))) {
$an = escape_data($_POST['user_sn']);
} else {
$an = FALSE;
echo '<p>Please enter a valid character name!</p>';
}
// Check for an email address.
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['user_email'])))) {
$e = escape_data($_POST['user_email']);
} else {
$e = FALSE;
echo '<p>Please enter a valid email address!</p>';
}
// Check for a username.
if ($an && $e) { // If everything's OK.
// Make sure the username is available.
$query = "SELECT user_id FROM user WHERE user_name='$u'";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 0) { // Available.
// Add the user.
$query = "INSERT INTO user (user_name, user_sn, user_email, user_race, user_spec, user_nature, user_cause, user_kingdom, user_find, user_recruit, user_signat, registration) VALUES ('$user_name', '$an','$e', '$user_race', '$user_spec', '$user_nature', '$user_cause', '$user_kingdom', '$user_find', '$user_recruit', '$user_signat', NOW() )";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.
// Send an email, if desired.
echo 'Thank you for registering!';
include ('incl/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p>';
}
} else { // The username is not available.
echo '<p>That username is already taken.</p>';
}
mysql_close(); // Close the database connection.
} else { // If one of the data tests failed.
echo '<p>Please try again.</p>';
}
} // End of the main Submit conditional.
I have gathered I need to use the mysql_insert_id to insert the user_id to the second query but I am quite unsure on how to implement this to my code.
does it go here :
$query = "INSERT INTO user (user_name, user_sn, user_email, user_race, user_spec, user_nature, user_cause, user_kingdom, user_find, user_recruit, user_signat, registration) VALUES ('$user_name', '$an','$e', '$user_race', '$user_spec', '$user_nature', '$user_cause', '$user_kingdom', '$user_find', '$user_recruit', '$user_signat', NOW() )";
$result = @mysql_query ($query); // Run the query.
$user_id = mysql_insert_id()
then the second query to insert into the second table?