please i am having the notice for undefined index, i tried to use isset funcion, though it worked for the notice to go away, but the notice now appears in the echo functions of the preset boxes
…
the register page was initially like
$submit = $_POST['register'];
//form data
$fullname = mysql_real_escape_string(htmlentities(strip_tags($_POST['fullname'])));
$username = strtolower(mysql_real_escape_string(htmlentities(strip_tags($_POST['username']))));
$password = mysql_real_escape_string(htmlentities(strip_tags($_POST['password'])));
$repeatpassword = mysql_real_escape_string(htmlentities(strip_tags($_POST['repeatpassword'])));
$email = mysql_real_escape_string(htmlentities(strip_tags($_POST['email'])));
$houseno = mysql_real_escape_string(htmlentities(strip_tags($_POST['houseno'])));
$addressa = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressa'])));
$addressb = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressb'])));
$addressc = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressc'])));
$county = mysql_real_escape_string(htmlentities(strip_tags($_POST['county'])));
$state = mysql_real_escape_string(htmlentities(strip_tags($_POST['state'])));
$country = mysql_real_escape_string(htmlentities(strip_tags($_POST['country'])));
$accept = mysql_real_escape_string(htmlentities(strip_tags($_POST['accept'])));
then i changed it to
if(isset($_POST['register'])){$submit = $_POST['register'];}
//form data
if(isset($_POST['fullname'])){$fullname = mysql_real_escape_string(htmlentities(strip_tags($_POST['fullname'])));}
if(isset($_POST['username'])){$username = strtolower(mysql_real_escape_string(htmlentities(strip_tags($_POST['username']))));}
if(isset($_POST['password'])){$password = mysql_real_escape_string(htmlentities(strip_tags($_POST['password'])));}
if(isset($_POST['repeatpassword'])){$repeatpassword = mysql_real_escape_string(htmlentities(strip_tags($_POST['repeatpassword'])));}
if(isset($_POST['email'])){$email = mysql_real_escape_string(htmlentities(strip_tags($_POST['email'])));}
if(isset($_POST['houseno'])){$houseno = mysql_real_escape_string(htmlentities(strip_tags($_POST['houseno'])));}
if(isset($_POST['addressa'])){$addressa = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressa'])));}
if(isset($_POST['addressb'])){$addressb = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressb'])));}
if(isset($_POST['addressc'])){$addressc = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressc'])));}
if(isset($_POST['county'])){$county = mysql_real_escape_string(htmlentities(strip_tags($_POST['county'])));}
if(isset($_POST['state'])){$state = mysql_real_escape_string(htmlentities(strip_tags($_POST['state'])));}
if(isset($_POST['country'])){$country = mysql_real_escape_string(htmlentities(strip_tags($_POST['country'])));}
if(isset($_POST['accept'])){$accept = mysql_real_escape_string(htmlentities(strip_tags($_POST['accept'])));}
(the notice was gone then started apperaring in the echo part
<div>
<label for='username' class='fixedwidth'>Choose a user name*</label>
<input type='text' name='username' id='username' value='<?[B]php echo $username; [/B]?>'/>
</div>
i guess i am not using the isset function correctly.please any advice
SpikeZ
July 21, 2013, 11:55am
2
You are checking if the username etc exists and then calling it anyway!
What you could do is set a ‘default’ value eg
if(isset($_POST['fullname'])){ $fullname = mysql_real_escape_string(htmlentities(strip_tags($_POST['fullname'])));} else { $fullname = '';}
or using a ternary operator
$fullname = isset($_POST['fullname']) ? mysql_real_escape_string(htmlentities(strip_tags($_POST['fullname']))) : '';
i have edited it but its now giving another notice of undefined variable on a different line 27 which starts
the editted code
{
$namecheck = mysql_query("SELECT username FROM reusers WHERE username='$username'");
$count = mysql_num_rows($namecheck);
the full code
<?php
echo "<h2>Register</h2>";
if(isset($_POST['register'])){ $submit = $_POST['register'];} else { $register = '';}
//form data
if(isset($_POST['fullname'])){ $fullname = mysql_real_escape_string(htmlentities(strip_tags($_POST['fullname'])));} else { $fullname = '';}
if(isset($_POST['username'])){ $username = strtolower(mysql_real_escape_string(htmlentities(strip_tags($_POST['username']))));} else { $username = '';}
if(isset($_POST['password'])){ $password = mysql_real_escape_string(htmlentities(strip_tags($_POST['password'])));} else { $password = '';}
if(isset($_POST['repeatpassword'])){ $repeatpassword = mysql_real_escape_string(htmlentities(strip_tags($_POST['repeatpassword'])));} else { $repeatpassword = '';}
if(isset($_POST['email'])){ $email = mysql_real_escape_string(htmlentities(strip_tags($_POST['email'])));} else { $email = '';}
if(isset($_POST['houseno'])){ $houseno = mysql_real_escape_string(htmlentities(strip_tags($_POST['houseno'])));} else { $houseno = '';}
if(isset($_POST['addressa'])){ $addressa = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressa'])));} else { $addressa = '';}
if(isset($_POST['addressb'])){ $addressb = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressb'])));} else { $addressb = '';}
if(isset($_POST['addressc'])){ $addressc = mysql_real_escape_string(htmlentities(strip_tags($_POST['addressc'])));} else { $addressc = '';}
if(isset($_POST['county'])){ $county = mysql_real_escape_string(htmlentities(strip_tags($_POST['county'])));} else { $county = '';}
if(isset($_POST['state'])){ $state = mysql_real_escape_string(htmlentities(strip_tags($_POST['state'])));} else { $state = '';}
if(isset($_POST['country'])){ $country = mysql_real_escape_string(htmlentities(strip_tags($_POST['country'])));} else { $country = '';}
if(isset($_POST['accept'])){ $accept = mysql_real_escape_string(htmlentities(strip_tags($_POST['accept'])));} else { $accept = '';}
if ($submit)
{
$namecheck = mysql_query("SELECT username FROM reusers WHERE username='$username'");
$count = mysql_num_rows($namecheck);
if($count!=0)
{
die("Username already taken!");
}
//$body = " Hello $fullname,\
\
Username $username,\
\
You registered and need to activate your account. Click the link below or paste it into the URL bar of your browser\
\
http://reacheasy.co.uk/activate.php?code=$code\
\
Thanks!";
//$body = " Hello $fullname,\
\
Username $username,\
\
Password $password ,\
\
You registered and need to activate your account, n\
Please keep this email safe as it contains your password . Click the link below or paste it into the URL bar of your browser\
\
http://reacheasy.co.uk/activate.php?code=$code\
\
Thanks!";
//check for registration form details
if ($fullname&&$username&&$password&&$repeatpassword&&$email&&$houseno&&$addressa&&$addressc&&$county&&$state&&$country)
{
if($accept == 1)
{
if ($password==$repeatpassword)
{
//check char lenght of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo '<span style="color: red;">Lenght of username or fullname is too long</span>';
}
else
{
//check password length
if(strlen($password)>25||strlen($password)<6)
{
echo'<span style="color: red;">Password must be between 6 and 25 characters</span>';
}
else
{
//check password length
$emailcheck = mysql_query("SELECT email FROM reusers WHERE email='$email'");
$ecount = mysql_num_rows($emailcheck);
if($ecount!=0)
{
echo'<span style="color: red;">email already registered Please sign in into your account to continue</span>';
}
else
{
//generate random code
$code = rand(11111111,99999999);
//send activation email
$to = $email;
$subject = "Activate your account";
$headers = "From: donotreply@reacheasy.co.uk";
$body = " Hello $fullname,\
\
Username $username,\
\
Password $password ,\
\
You registered and need to activate your account, n\
Please keep this email safe as it contains your password . Click the link below or paste it into the URL bar of your browser\
\
http://reacheasy.co.uk/activate.php?code=$code\
\
Thanks!";
if (!mail($to,$subject,$body,$headers))
echo "We couldn't sign you up at this time. Please try again later.";
else
{
//register the user!
//encript password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
$queryreg = mysql_query("
INSERT INTO reusers VALUES ('','$fullname','$username','$password','$email','$code','0','$houseno','$addressa','$addressb','$addressc','$county','$state','$country')
");
die("You have been registered successfully! Please check your email ($email) to activate your account<a href='index.php'>Return to login page</a>");
}
}
}
}
}
else
echo'<span style="color: red;">Your passwords do not match!</span>';
}
else
echo'<span style="color: red;">Please read and accept Terms and Conditions before registering!</span>';
}
else
echo '<span style="color: red;">Please fill in <b>all</> fields!</span>';
}
?>
Kinwoh
July 21, 2013, 12:49pm
4
$namecheck = mysql_query("SELECT `username` FROM `reusers` WHERE `username` = '$username'");
$count = mysql_num_rows($namecheck);
// MySQL query in a variable
tried it but its still given notice
Notice: Undefined variable: submit in /Users/mgltd/Sites/transpase/reregister.php on line 27
if ($submit)
{
$namecheck = mysql_query("SELECT username FROM reusers WHERE username='$username'");
$count = mysql_num_rows($namecheck);