/    Sign up×
Community /Pin to ProfileBookmark

php registration code won’t stop giving me the same error over and over

Here is the code please have a look at it for me and see if you can find my errors i am a newbie to coding first time actually making a registration code.
i keep getting the same error over and over and won’t submit to database also: This is the error:[COLOR=”Red”]You must enter a valid email address to register.
[/COLOR]

<?php
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
session_start();

include(“connect.php”);

if(isset($_POST[‘submit’])){

//get all posted data
$username = $_POST[‘user’];
$password = $_
POST[‘pass’];
$confirmpassword = $_POST[‘confirmpassword’];
$email = $_
POST[’email’];

if($username && $password && $confirmpassword && $email)
{
if((strlen($username)<=6) || (strlen($password)<=6))
{
echo “The username or password is too short!”;
}
else
{
if ($password === $confirmpassword)
{
$sql = mysql_query(“SELECT * FROM users WHERE username=’$username'”);
$numrows = mysql_num_rows($sql) or die(mysql_error());
if ($numrows == 0)
{
echo “The username ‘$username’ already exists!”;
}
else
{
$md5password =md5($password);

mysql_query(“INSER INTO users (id, username, $md5password, email) VALUES
(”,’$username’,’$confirmpassword’)”);
echo “Registration Successful! <a href=’login.php’>Click here to login now!</a>”;
}

}
else
{
echo “Passwords do not match enter both fields!!”;
}
}
}
else
{
die(“Please enter all the required fields!!”);
}

}

?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 08.2011 — Here's your code wrapped in this forum's [noparse][code=php]...[/code][/noparse] tags, which should make it a lot easier for us to help you:
[code=php]
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
session_start();

include("connect.php");

if(isset($_POST['submit'])){

//get all posted data
$username = $_POST['user'];
$password = $_POST['pass'];
$confirmpassword = $_POST['confirmpassword'];
$email = $_POST['email'];

if($username && $password && $confirmpassword && $email)
{
if((strlen($username)<=6) || (strlen($password)<=6))
{
echo "The username or password is too short!";
}
else
{
if ($password === $confirmpassword)
{
$sql = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($sql) or die(mysql_error());
if ($numrows == 0)
{
echo "The username '$username' already exists!";
}
else
{
$md5password =md5($password);

mysql_query("INSER INTO users (id, username, $md5password, email) VALUES
('','$username','$confirmpassword')");
echo "Registration Successful! <a href='login.php'>Click here to login now!</a>";
}
}
else
{
echo "Passwords do not match enter both fields!!";
}
}
}
else
{
die("Please enter all the required fields!!");
}

}

?>[/code]
Copy linkTweet thisAlerts:
@NogDogAug 08.2011 — The error message you described, "You must enter a valid email address to register," is not anywhere in that PHP code. Could it be a JavaScript function on the form page itself?

A different problem I did notice is this line:
[code=php]
mysql_query("INSER INTO users (id, username, $md5password, email) VALUES
('','$username','$confirmpassword')");
[/code]

Problem #1 is that your probably want "password" instead of "$md5password" in the field list (the first set of parentheses, and the second problem is that you list 4 fields but only supply 3 values (looks like you left out the email address value).
×

Success!

Help @gazaian1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...