I am trying to do a registration form that registers a user in a database (MySQL).
The code is supposed to register:
- Name
- Surname
- Username
- Password
- Security Question
- Security Answer
The code, before saving to the table, checks whether the username or password already exists, and if they do it echoes an error message, and if not, it saves to the db.
However, on page load, I'm getting these errors:
Notice: Undefined index: Name in C:\xampp\htdocs\Task2\registration.php on line 216
Notice: Undefined index: Surname in C:\xampp\htdocs\Task2\registration.php on line 217
Notice: Undefined index: Username in C:\xampp\htdocs\Task2\registration.php on line 219
Notice: Undefined index: Email in C:\xampp\htdocs\Task2\registration.php on line 221
Notice: Undefined index: C_Email in C:\xampp\htdocs\Task2\registration.php on line 222
Notice: Undefined index: password in C:\xampp\htdocs\Task2\registration.php on line 224
Notice: Undefined index: c_password in C:\xampp\htdocs\Task2\registration.php on line 225
Notice: Undefined index: SecQ in C:\xampp\htdocs\Task2\registration.php on line 227
Notice: Undefined index: SecA in C:\xampp\htdocs\Task2\registration.php on line 228
Notice: Undefined variable: mysql_connect in C:\xampp\htdocs\Task2\registration.php on line 231
Fatal error: Function name must be a string in C:\xampp\htdocs\Task2\registration.php on line 231
This is the code:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Registration
Name
Surname
Username
Email
Confirm Email
Password
Confirm Password
Security Question
Security Answer
style="font-family: Arial,Helvetica,sans-serif">
$Name = $_POST['Name'];
$Surname = $_POST['Surname'];
$Username = $_POST['Username'];
$Email = $_POST['Email'];
$C_Email = $_POST['C_Email'];
$Password = $_POST['password'];
$C_Password = $_POST['c_password'];
$SecQ = $_POST['SecQ'];
$SecA = $_POST['SecA'];
$mysql_connect ('localhost', 'admin', 'storefile1234');
mysql_select_db ("storefile");
$check_username = mysql_query("SELECT FROM users WHERE username = '$Username'");
$check_email = mysql_query("SELECT FROM users WHERE email = '$Email'");
if ($Name == null || $Surname== null || $Username == null || $Password == null || $C_Password == null || $Email == null || $C_Email == null || $SecQ == null || $SecA == null ) {
echo "Missing details. Please enter all fields.";
} else {
if(mysql_num_rows($check_username) != 0 && mysql_num_rows($check_email) != 0)
{
echo "Username/Email already exists";
}
if ($Email == $C_Email && $Password == $C_Password) {
$query = "INSERT INTO users (Username, Name,Surname, Password, Email, SecQ, SecA) VALUES ('NULL', ".$Username."', ".$Name."', ".$Surname."', ".$Password."', ".$SecQ."', ".$SecA."', ".$Email.')"';
mysql_query($query) or die ('Error registering.');
echo "Greetings, ".$Name.", you have been registered. ";
} else {
echo "Error registering your account. Please try again.";
}
}
?>
Any help would be appreciated.
Thanks!
No comments:
Post a Comment