Hello Experts,
I am having a problem with my form results INSERTing into the database. I have a mysql INSERT stmt that I have tried to get working. BAsically, it gives me the error from !sql
if (!$sql) {
echo 'There has been an error creating you account, please conact the site manager.';
Here is my entire page with the query.. I think something is wrong with my query but not sure how to trouble it..
Thanks for your help...
<?PHP
include('.db.php');
include('common.php');
// Let's Grab the post vars
$status = "1";
$user_level = $_POST['user_level'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$business_name = $_POST['business_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$account = $_POST['account'];
$newsletter = $_POST['newsletter'];
// Used for debugging. Turn on and off in the common.php file
if ($debug == "ON") {
echo "the status is" .$status . "<br/>";
echo "the user level is" .$user_level . "<br/>";
echo "the first name is" .$first_name . "<br/>";
echo "the last name is" .$last_name . "<br/>";
echo "the email addy is" .$email_address . "<br/>";
echo "the username is" .$username . "<br/>";
echo "the business name is" .$business_name . "<br/>";
echo "the address is" .$address . "<br/>";
echo "the city is" .$city . "<br/>";
echo "the state is" .$state . "<br/>";
echo "the zip is" .$zip . "<br/>";
echo "the phone is" .$phone . "<br/>";
echo "the account is" .$account . "<br/>";
echo "the newsletter is" .$newsletter . "<br/>";
}
// Strip slashes
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_addres
s);
$username = stripslashes($username);
$business_name = stripslashes($business_nam
e);
$address = stripslashes($address);
$city = stripslashes($city);
$state = stripslashes($state);
$zip = stripslashes($zip);
$phone = stripslashes($phone);
// Error checking goes here
// Make sure that the email address hasn't been taken
$sql_email_check = mysql_query("SELECT email_address FROM members
WHERE email_address ='$email_address'");
// Check to make sure user name hasn't been taken
$sql_username_check = mysql_query("SELECT username FROM members
WHERE username = '$username'");
$email_check = mysql_num_rows($sql_email_
check);
$username_check = mysql_num_rows($sql_userna
me_check);
// If stmt to echo user a messsage telling them that the email / uername exist
if (($email_check > 0) || ($username_check > 0 )) {
echo "<span class=\"maintext\"> Please fix the following errors:</span> <br/>";
if ($email_check > 0) {
echo "<span class=\"maintext\"> <strong> Your email address has already been used by another
member <br> in our database. Please submit a different email address!</strong></span><b
r/>";
unset($email_address);
}
if ($username_check > 0) {
echo "<span class=\"maintext\"><strong
>The username that you have selected has already been used by
another member<br/>in our database. Please choose a different username!</strong></span><
br/>";
unset($username);
}
echo "<br><br>";
echo "<a href=\"index.php?content=j
oin2\">Go Back</a>";
// Exit the script so that we don't create this account
exit();
}
// if everything is successfull let's set up the account
// Random password generator
function makeRandomPassword() {
$salt = "AaBbCcDdEeFfGgHhIiJjKkLlM
mNnOoPpQqR
rSsTtUuVvX
xYyZz01234
56789";
srand((double)microtime()*
1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % strlen($salt);
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("INSERT INTO `members` (`id`, `status`, `first_name`, `last_name`,
`address`, `city`, `state`, `zip`, `phone`, `business_name`, `email_address`,
`signup_date`, `verified`, `last_login`, `bio`, `admin_access`, `username`,
`password`, `account`, `user_level`, `newsletter`) VALUES ('$id', '$status', '$first_name', '$last_name',
'$address', '$city', '$state', '$zip', '$phone', '$business_name', '$email_address', '$signup_date', 'verified', '$last_login', '$bio', '$admin_access',
'$username', '$db_password', '$account', '$user_level', '$newsletter', now()
or die (mysql_error()");
if (!$sql) {
echo 'There has been an error creating you account, please conact the site manager.';
}else{
$id = mysql_insert_id();
// Let's mail the user
$subject = "Your membership at Bell Plantation!";
$message = "Dear $first_name $last_name, \n
Thank you for registering at our website,
http://www.bellplantation.com! You are ywp steps away from logging in and accessing our exclusive member's area.
\n To activate your membership, Please click here
http://www.dannykelly.com/bell/index.php?content=activate&id=$id&code=$db_password Once you activate your memebership, you will be able to login
with the following information:
Username: $username
Password: $random_password
Thanks!
Thanks!
The Bell Plantation Team
This is an automated response, please do not reply!";
mail($email_address, $subject, $message,
"From: Bell Plantation Webmaster< registrations@bellplantati
on.com>\n
X-Mailer: PHP/" . phpversion());
// Email the administrator
$mailer = &new Email;
$mailer->ToMail = "dk4210@planttel.net";
$mailer->FromMail = "System@bellplantation.com
";
$mailer->FromName = "Bell Plantation Administrator";
$mailer->Subject = "New Member at bellplantation.com [$username]";
$mailer->Message = "Hi,\n\n".
"A new member has just signed up ".
"at BellPlantation.com! Here's their ".
" information:\n\n".
"=====================\n".
"First Name: $_POST[first_name]\n".
"Last name: $_POST[last_name]\n\n".
"Email Address: ".
"$_POST[email_address]\n\n
".
"UserID: $username\n\n".
"This user is from $city, $state\n\n".
"=====================\n\n
".
"Thank you,\n\n".
"Bell Plantation System notification\n";
$mailer->SendMail();
?>
<br><br><center><br><br><d
iv class="boxheader">Congratu
lations!!<
/div><br><
div class="maintext"> Your membership information has been mailed to your email address!
Please check it and follow the directions!</div></center>
<br><br><center><a href="index.php"><div class="maintext"> Click here to go back home<div></a></center><br>
<br>
<?
}
?>