All of a sudden my php code has come up with :
Notice: Undefined index: submit in C:\xampp\htdocs\globalautoparts\register.php on line 36
Notice: Undefined index: fullname in C:\xampp\htdocs\globalautoparts\register.php on line 40
Notice: Undefined index: username in C:\xampp\htdocs\globalautoparts\register.php on line 41
Notice: Undefined index: password in C:\xampp\htdocs\globalautoparts\register.php on line 42
Notice: Undefined index: repeatpassword in C:\xampp\htdocs\globalautoparts\register.php on line 43
Notice: Undefined index: email in C:\xampp\htdocs\globalautoparts\register.php on line 45
on the registration page.
How do i fix it?
This is my code:
Global Autoparts | Home
Think outside of the box!
Registering with Global Auto Parts means you have access to super-fast online orders and total user customization, so you wont have to wait in a line again!
Register to become apart of the global community!
echo "
Registration Page.
";
$submit = $_POST['submit'];
//form data
$fullname = strip_tags($_POST['fullname']);
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date("Y-m-d");
$email = $_POST['email'];
if ($submit)
{
//open database
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin"); //select database
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);
if ($count!=0)
{
die("Username already taken! Go back to try again?");
}
// check for existence
if($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
//check char length of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or fullname is too long!";
}
else{
//check password length
if (strlen($password)>25||strlen($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else{
//register the user!
// encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
//generate random number for activation process
$random = rand(23456789,98765432);
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$fullname','$username','$password','$email','$date','$random','0')
");
$lastid = mysql_insert_id();
//send activation email
ini_set("SMTP",$server);
$to = $email;
$subject = "Activate your account!";
$headers = "From: Global Auto Parts";
$server = "localhost";
$body = "
Hello $fullname,\n\n
You need to activate your account with the link below:
http://localhost/globalautoparts/activate.php?=$lastid&code=$random \n\n
Thanks.
";
//function to send mail
mail($to, $subject, $body, $headers);
die("You have been registered! Check your email to activate your account!");
}
}
}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in all fields!";
}
?>
Answer
As the other guys suggested, you could
Change the Error Reporting Level
By running this code at the top of your script: error_reporting(E_ALL ^ E_NOTICE)
Or, it might be a better idea to actually check whether those variables were posted before you use them.
Quick and Dirty fix is to do this:
@$_POST['submit']
The @ sign will suppress any errors and return false in place of the string. Now that practice is generally frowned upon.
If you want a cleaner method, I would do this:
$post = array('fullname'=>'','username'=>'','password'=>'','repeatpassword'=>'');
if($_POST) $post = array_merge($post, $_POST);
$fullname = strip_tags($post['fullname']);
$username = strtolower(strip_tags($post['username']));
$password = strip_tags($post['password']);
$repeatpassword = strip_tags($post['repeatpassword']);
Then you'll never have a error about missing indexes, and you can set the default values to whatever you like.
Good luck
No comments:
Post a Comment