Jump to content

[SOLVED] Problem with registration script


Demont

Recommended Posts

I created a registration script, and created the Database tables, yet when I test it, it keeps saying "You did not complete all required fileds" and I don't know what is wrong...

 

Here's the code.

 

<?php 
// Connects to your Database 
mysql_connect("localhost", "username", "password") or die(mysql_error()); 
mysql_select_db("database") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['gender'] | !$_POST['race'] | !$_POST['class'] | !$_POST['hair'] | !$_POST['eyes'] | !$_POST['skin'] | !$_POST['email'] | !$_POST['email2']) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. 
');
}
if ($_POST['email'] != $_POST['email2']) {
die('Your emails do not match.
');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (username, password, gender, race, class, hair, eyes, skin, email)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['gender']."', '".$_POST['race']."', '".$_POST['class']."', '".$_POST['hair']."', '".$_POST['eyes']."', '".$_POST['skin']."', '".$_POST['email']."')";
$add_member = mysql_query($insert);
?>


<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>

<?php 
} 
else 
{ 
?>
<center>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>Gender:</td><td>
Male<input type="radio" name="male" value="male">
Female<input type="radio" name="female" value="female">
</td></tr>
<tr><td>Race:</td><td>
<SELECT NAME="race" SIZE="1">
<OPTION SELECTED>Elf
<OPTION>Dwarf
<OPTION>Human
</SELECT>
</td></tr>
<tr><td>Class:</td><td>
<SELECT NAME="class" SIZE="1">
<OPTION SELECTED>Warrior
<OPTION>Ranger
<OPTION>Mage
</SELECT>
</td></tr>
<tr><td>Hair:</td><td>
<SELECT NAME="hair" SIZE="1">
<OPTION SELECTED>Blonde
<OPTION>Brown
<OPTION>Red
<OPTION>Dark
<OPTION>White
<OPTION>Silver
</SELECT>
</td></tr>
<tr><td>Eyes:</td><td>
<SELECT NAME="eyes" SIZE="1">
<OPTION SELECTED>Blue
<OPTION>Green
<OPTION>Brown
<OPTION>Hazel
<OPTION>Bi-Colored
</SELECT>
</td></tr>
<tr><td>Skin:</td><td>
<SELECT NAME="skin" SIZE="1">
<OPTION SELECTED>Tanned
<OPTION>Light
<OPTION>Dark
<OPTION>Pale
<OPTION>Blotched
</SELECT>
</td></tr>
<tr><td>Email:</td><td>
<input type="text" name="email" maxlength="60">
</td></tr>
<tr><td>Confirm Email:</td><td>
<input type="text" name="email2" maxlength="60">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>
Please make sure emails are correct, as it is the only way you will be able to retrieve a lost password.
<br>
<a href="index.php">Home</a></center>

Link to comment
https://forums.phpfreaks.com/topic/78820-solved-problem-with-registration-script/
Share on other sites

Run your form in a browser. Have the script in an editor. While the form is in the browser, use the edit to put this at the top of the script:

 

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
die();

 

Fill out the form and submit. The page will display all the variables it sees coming back in. Check those against you IF logic.

 

PhREEEk

I created a registration script, and created the Database tables, yet when I test it, it keeps saying "You did not complete all required fileds" and I don't know what is wrong...

 

Here's the code.

 

<?php 
// Connects to your Database 
mysql_connect("localhost", "username", "password") or die(mysql_error()); 
mysql_select_db("database") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['gender'] | !$_POST['race'] | !$_POST['class'] | !$_POST['hair'] | !$_POST['eyes'] | !$_POST['skin'] | !$_POST['email'] | !$_POST['email2']) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. 
');
}
if ($_POST['email'] != $_POST['email2']) {
die('Your emails do not match.
');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (username, password, gender, race, class, hair, eyes, skin, email)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['gender']."', '".$_POST['race']."', '".$_POST['class']."', '".$_POST['hair']."', '".$_POST['eyes']."', '".$_POST['skin']."', '".$_POST['email']."')";
$add_member = mysql_query($insert);
?>


<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>

<?php 
} 
else 
{ 
?>
<center>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>Gender:</td><td>
Male<input type="radio" name="male" value="male">
Female<input type="radio" name="female" value="female">
</td></tr>
<tr><td>Race:</td><td>
<SELECT NAME="race" SIZE="1">
<OPTION SELECTED>Elf
<OPTION>Dwarf
<OPTION>Human
</SELECT>
</td></tr>
<tr><td>Class:</td><td>
<SELECT NAME="class" SIZE="1">
<OPTION SELECTED>Warrior
<OPTION>Ranger
<OPTION>Mage
</SELECT>
</td></tr>
<tr><td>Hair:</td><td>
<SELECT NAME="hair" SIZE="1">
<OPTION SELECTED>Blonde
<OPTION>Brown
<OPTION>Red
<OPTION>Dark
<OPTION>White
<OPTION>Silver
</SELECT>
</td></tr>
<tr><td>Eyes:</td><td>
<SELECT NAME="eyes" SIZE="1">
<OPTION SELECTED>Blue
<OPTION>Green
<OPTION>Brown
<OPTION>Hazel
<OPTION>Bi-Colored
</SELECT>
</td></tr>
<tr><td>Skin:</td><td>
<SELECT NAME="skin" SIZE="1">
<OPTION SELECTED>Tanned
<OPTION>Light
<OPTION>Dark
<OPTION>Pale
<OPTION>Blotched
</SELECT>
</td></tr>
<tr><td>Email:</td><td>
<input type="text" name="email" maxlength="60">
</td></tr>
<tr><td>Confirm Email:</td><td>
<input type="text" name="email2" maxlength="60">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>
Please make sure emails are correct, as it is the only way you will be able to retrieve a lost password.
<br>
<a href="index.php">Home</a></center>

 

From what I can see, you're trying to use 'or' try it like this:

 

<?php


//This makes sure they did not leave any fields blank
if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['gender'] || !$_POST['race'] || !$_POST['class'] || !$_POST['hair'] || !$_POST['eyes'] || !$_POST['skin'] || !$_POST['email'] || !$_POST['email2']) {
die('You did not complete all of the required fields');
}

?>

change

 


<?php 

if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['gender'] | !$_POST['race'] | !$_POST['class'] | !$_POST['hair'] | !$_POST['eyes'] | !$_POST['skin'] | !$_POST['email'] | !$_POST['email2']) {
die('You did not complete all of the required fields');
}

?>

 

to

 

[code]

<?php 

if (($_POST['username'] == "")||($_POST['pass']=="")||($_POST['pass2']=="")||($_POST['gender']=="")||($_POST['race']=="")||($_POST['class']=="") || ($_POST['hair']=="")||($_POST['eyes']=="")||($_POST['skin']=="" )||($_POST['email']=="")||($_POST['email2']=="")) {
die('You did not complete all of the required fields');
}

?>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.