09-17-2011, 03:51 AM
Hi, i am trying to create a registration page for my website, however when i test it and click the submit button i get this error,
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2"
I have tried everything to try and fix this but cannot do it.
Anyone have any ideas,
Heres my code
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2"
I have tried everything to try and fix this but cannot do it.
Anyone have any ideas,
Heres my code
PHP Code:
<?php
// Code only runs if submit button is pressed
if (isset ($_POST['firstname'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$paypal_email = $_POST['paypal_email'];
$country = $_POST['country'];
$kingdom_name = $_POST['kingdom_name'];
$kingdom_motto = $_POST['kingdom_motto'];
$referal = $_POST['referal'];
$newsletter = $_POST['newsletter'];
include_once "connect_to_mysql.php";
$emailCHecker = mysql_real_escape_string($email);
$emailCHecker = eregi_replace("`", "", $emailCHecker);
$usernameCHecker = mysql_real_escape_string($username);
$usernameCHecker = eregi_replace("`", "", $usernameCHecker);
// Database duplicate e-mail check setup for use below in the error handling if else conditionals
$sql_email_check = mysql_query("SELECT email FROM user_info WHERE email='$emailCHecker'");
$email_check = mysql_num_rows($sql_email_check);
$sql_username_check = mysql_query("SELECT username FROM user_info WHERE username='$usernameCHecker'");
$username_check = mysql_num_rows($sql_username_check);
// Error handling for missing data
if ((!$firstname) || (!$lastname) || (!$username) || (!$email) || (!$password) || (!$cpassword) || (!$paypal_email) || (!$kingdom_name) || (!$kingdom_motto)) {
$errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
if(!$firstname){
$errorMsg .= ' * Firstname<br />';
}
if(!$lastname){
$errorMsg .= ' * Lastname<br />';
}
if(!$username){
$errorMsg .= ' *Username<br />';
}
if(!$email){
$errorMsg .= ' * Email<br />';
}
if(!$password){
$errorMsg .= ' * Password<br />';
}
if(!$cpassword){
$errorMsg .= ' * Confirmation Password<br />';
}
if(!$paypal_email){
$errorMsg .= ' * Paypal Email<br />';
}
if(!$kingdom_name){
$errorMsg .= ' * Kingdom Name<br />';
}
if(!$kingdom_motto){
$errorMsg .= ' * Kingdom Password<br />';
}
} else if ($password != $cpassword) {
$errorMsg = 'ERROR: Your Password fields below do not match<br />';
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />";
} else if ($username_check > 0){
$errorMsg = "<u>ERROR:</u><br />Username selected is already in use. Please choose another.<br />";
} else { // Error handling is ended
// Add MD5 Hash to the password
$password = md5($password);
// Add user info into the database table
$sql = mysql_query("INSERT INTO user_info (firstname, lastname, username, email, password, sign_up_date)
VALUES('$firstname','$lastname','$username','$email','$password', now()")
or die (mysql_error());
$id = mysql_insert_id();
mkdir("members/$id", 0755);
include_once 'msgToUser.php';
exit();
} // Close else
} else { // if the form is not posted with variables, place default empty variables so no warnings or errors show
$errorMsg = "";
$firstname = "";
$lastname = "";
$username = "";
$email = "";
$password = "";
$cpassword = "";
$paypal_email = "";
$kingdom_name = "";
$kingdom_motto = "";
$referal = "";
}
?>