Hey guys... I'm having a brief issue with my error checking...
See, when I took the code off Freak's tutorial ( http://www.phpfreaks.com/tutorials/40/0.php ) and put it into my own little script, it was the error checking for required fields that was the problem... The required fields WOULD be filled out... but then it wouldn't post the data into the database.... here's the code to the form...
< ?
include 'db.inc.php';
// Define post fields into simple variables
$user_name = $_POST['user_name'];
$user_password = $_POST['user_password'];
$user_birthdate = $_POST['user_birthdate'];
$user_sex = $_POST['user_sex'];
$user_country = $_POST['user_country'];
$user_occupation = $_POST['user_occupation'];
$user_location = $_POST['user_location'];
$user_msn = $_POST['user_msn'];
$user_yahoo = $_POST['user_yahoo'];
$user_aim = $_POST['user_aim'];
$user_icq = $_POST['user_icq'];
$user_website = $_POST['user_website'];
$user_email = $_POST['user_email'];
$user_interests = $_POST['user_interests'];
$user_favwebsite1 = $_POST['user_favwebsite1'];
$user_favwebsite2 = $_POST['user_favwebsite2'];
$user_favwebsite3 = $_POST['user_favwebsite3'];
$user_favwebsite4 = $_POST['user_favwebsite4'];
$user_favmovies = $_POST['user_favmovies'];
$user_favbands = $_POST['user_favbands'];
$user_favmusic = $_POST['user_favmusic'];
$user_favartists = $_POST['user_favartists'];
$user_favwriters = $_POST['user_favwriters'];
$user_operating = $_POST['user_operating'];
$user_mp3 = $_POST['user_mp3'];
$user_wallpaper = $_POST['user_wallpaper'];
$user_quote = $_POST['user_quote'];
$user_tools = $_POST['user_tools'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$user_name = stripslashes($user_name);
$user_password = stripslashes($user_password);
$user_birthdate = stripslashes($user_birthdate);
$user_sex = stripslashes($user_sex);
$user_country = stripslashes($user_country);
$user_occupation = stripslashes($user_occupation);
$user_location = stripslashes($user_country);
$user_msn = stripslashes($user_msn);
$user_yahoo = stripslashes($user_yahoo);
$user_aim = stripslashes($user_aim);
$user_icq = stripslashes($user_icq);
$user_website = stripslashes($user_website);
$user_email = stripslashes($user_email);
$user_interests = stripslashes($user_interests);
$user_favwebsite1 = stripslashes($user_favwebsite1);
$user_favwebsite2 = stripslashes($user_favwebsite2);
$user_favwebsite3 = stripslashes($user_favwebsite3);
$user_favwebsite4 = stripslashes($user_favwebsite4);
$user_favmovies = stripslashes($user_favmovies);
$user_favbands = stripslashes($user_favbands);
$user_favmusic = stripslashes($user_favmusic);
$user_favartists = stripslashes($user_favartists);
$user_favwriters = stripslashes($user_favwriters);
$user_operating = stripslashes($user_operating);
$user_mp3 = stripslashes($user_mp3);
$user_wallpaper = stripslashes($user_wallpaper);
$user_quote = stripslashes($user_quote);
$user_tools = stripslashes($user_tools);
/* This is where we WOULD check for required fields... don't know white how though */
/* Everything has passed both error checks that we have done.
It's time to create the account! */
// Enter info into the Database.
$sql = "INSERT INTO tu_users (user_name, user_password, user_birthdate, user_sex, user_country, user_occupation, user_location, user_msn, user_yahoo, user_aim, user_icq, user_website, user_email, user_interests, user_favwebsite1, user_favwebsite2, user_favwebsite3, user_favwebsite4, user_favmovies, user_favbands, user_favmusic, user_favartists, user_favwriters, user_operating, user_mp3, user_wallpaper, user_quote, user_tools, activated) VALUES('$user_name', '$user_password', '$user_birthdate', '$user_sex', '$user_country', '$user_occupation', '$user_location', '$user_msn', '$user_yahoo', '$user_aim', '$user_icq', '$user_website', '$user_email', '$user_interests', '$user_favwebsite1', '$user_favwebsite2', '$user_favwebsite3', '$user_favwebsite4', '$user_favmovies', '$user_favbands', '$user_favmusic', '$user_favartists', '$user_favwriters', '$user_operating', '$user_mp3', '$user_wallpaper', '$user_quote', '$user_tools', 1)";
mysql_query($sql);
if (mysql_errno())
{
echo "error: < P > $sql < P > " . mysql_error();
exit;
}
? >
Here's the code to the error checking originally:
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information!
';
if(!$first_name){
echo "First Name is a required field. Please enter it below.
";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.
";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.
";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.
";
}
include 'join_form.html'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
Please don't ask me to re-add the error checking and the exit() cause it doesn't work..... however, is there some other way I can define the required fields that WOULD allow the data to post to the db, and then redirect to another page, say, registrationsuccess.php or something?
Right now it posts to the database, but I can't define required fields because it would just load register.php (the above file), and not post anything else...
Thanks guys... if I can get this to work, you'll have the endearing love of a newbie...
Seven years of HTML, almost 3 months with PHP...
-Shade
See, when I took the code off Freak's tutorial ( http://www.phpfreaks.com/tutorials/40/0.php ) and put it into my own little script, it was the error checking for required fields that was the problem... The required fields WOULD be filled out... but then it wouldn't post the data into the database.... here's the code to the form...
< ?
include 'db.inc.php';
// Define post fields into simple variables
$user_name = $_POST['user_name'];
$user_password = $_POST['user_password'];
$user_birthdate = $_POST['user_birthdate'];
$user_sex = $_POST['user_sex'];
$user_country = $_POST['user_country'];
$user_occupation = $_POST['user_occupation'];
$user_location = $_POST['user_location'];
$user_msn = $_POST['user_msn'];
$user_yahoo = $_POST['user_yahoo'];
$user_aim = $_POST['user_aim'];
$user_icq = $_POST['user_icq'];
$user_website = $_POST['user_website'];
$user_email = $_POST['user_email'];
$user_interests = $_POST['user_interests'];
$user_favwebsite1 = $_POST['user_favwebsite1'];
$user_favwebsite2 = $_POST['user_favwebsite2'];
$user_favwebsite3 = $_POST['user_favwebsite3'];
$user_favwebsite4 = $_POST['user_favwebsite4'];
$user_favmovies = $_POST['user_favmovies'];
$user_favbands = $_POST['user_favbands'];
$user_favmusic = $_POST['user_favmusic'];
$user_favartists = $_POST['user_favartists'];
$user_favwriters = $_POST['user_favwriters'];
$user_operating = $_POST['user_operating'];
$user_mp3 = $_POST['user_mp3'];
$user_wallpaper = $_POST['user_wallpaper'];
$user_quote = $_POST['user_quote'];
$user_tools = $_POST['user_tools'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$user_name = stripslashes($user_name);
$user_password = stripslashes($user_password);
$user_birthdate = stripslashes($user_birthdate);
$user_sex = stripslashes($user_sex);
$user_country = stripslashes($user_country);
$user_occupation = stripslashes($user_occupation);
$user_location = stripslashes($user_country);
$user_msn = stripslashes($user_msn);
$user_yahoo = stripslashes($user_yahoo);
$user_aim = stripslashes($user_aim);
$user_icq = stripslashes($user_icq);
$user_website = stripslashes($user_website);
$user_email = stripslashes($user_email);
$user_interests = stripslashes($user_interests);
$user_favwebsite1 = stripslashes($user_favwebsite1);
$user_favwebsite2 = stripslashes($user_favwebsite2);
$user_favwebsite3 = stripslashes($user_favwebsite3);
$user_favwebsite4 = stripslashes($user_favwebsite4);
$user_favmovies = stripslashes($user_favmovies);
$user_favbands = stripslashes($user_favbands);
$user_favmusic = stripslashes($user_favmusic);
$user_favartists = stripslashes($user_favartists);
$user_favwriters = stripslashes($user_favwriters);
$user_operating = stripslashes($user_operating);
$user_mp3 = stripslashes($user_mp3);
$user_wallpaper = stripslashes($user_wallpaper);
$user_quote = stripslashes($user_quote);
$user_tools = stripslashes($user_tools);
/* This is where we WOULD check for required fields... don't know white how though */
/* Everything has passed both error checks that we have done.
It's time to create the account! */
// Enter info into the Database.
$sql = "INSERT INTO tu_users (user_name, user_password, user_birthdate, user_sex, user_country, user_occupation, user_location, user_msn, user_yahoo, user_aim, user_icq, user_website, user_email, user_interests, user_favwebsite1, user_favwebsite2, user_favwebsite3, user_favwebsite4, user_favmovies, user_favbands, user_favmusic, user_favartists, user_favwriters, user_operating, user_mp3, user_wallpaper, user_quote, user_tools, activated) VALUES('$user_name', '$user_password', '$user_birthdate', '$user_sex', '$user_country', '$user_occupation', '$user_location', '$user_msn', '$user_yahoo', '$user_aim', '$user_icq', '$user_website', '$user_email', '$user_interests', '$user_favwebsite1', '$user_favwebsite2', '$user_favwebsite3', '$user_favwebsite4', '$user_favmovies', '$user_favbands', '$user_favmusic', '$user_favartists', '$user_favwriters', '$user_operating', '$user_mp3', '$user_wallpaper', '$user_quote', '$user_tools', 1)";
mysql_query($sql);
if (mysql_errno())
{
echo "error: < P > $sql < P > " . mysql_error();
exit;
}
? >
Here's the code to the error checking originally:
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information!
';
if(!$first_name){
echo "First Name is a required field. Please enter it below.
";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.
";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.
";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.
";
}
include 'join_form.html'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
Please don't ask me to re-add the error checking and the exit() cause it doesn't work..... however, is there some other way I can define the required fields that WOULD allow the data to post to the db, and then redirect to another page, say, registrationsuccess.php or something?
Right now it posts to the database, but I can't define required fields because it would just load register.php (the above file), and not post anything else...
Thanks guys... if I can get this to work, you'll have the endearing love of a newbie...
Seven years of HTML, almost 3 months with PHP...
-Shade
