Jump to content


Photo

Registration Script


  • Please log in to reply
3 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 June 2006 - 03:08 AM

error messages i made display when the form first loads which shouldnt happen, also if the errors happen it still writes whats left to the databasE! i cant make any sense of it, can anyone help me out?

<?php

include('dbconnect.php');

$USERNAME = $_POST['username'];
$PASSWORD = $_POST['password'];
$PASSWORD2 = $_POST['password2'];
$EMAIL = $_POST['email'];

$IPADDRESS = $_SERVER['REMOTE_ADDR'];
$JOINDATE = date('m-d-Y');

if($USERNAME==NULL || $PASSWORD==NULL || $PASSWORD2==NULL || $EMAIL==NULL)
{
echo "ALL fields must be completed before continuing registration.<Br />";
}

if($PASSWORD!=$PASSWORD2)
{
echo "Both passwords must match in order to continue.<Br />";
}

if(strlen($USERNAME<4 || $USERNAME>16))
{
echo "Username must be between 4 and 16 characters.<Br />";
}

if(strlen($PASSWORD<4 || $PASSWORD>16))
{
echo "Password must be between 4 and 16 characters.<Br />";
}

if(strlen($EMAIL<4 || $PASSWORD>24))
{
echo "eMail must be between 4 and 24 characters.<Br />";
}

echo "
<form action=\"\" method=POST>
*Username: <input type=text name=username>
<Br />
*Password: <input type=password name=password>
<Br />
*Confirm Password: <input type=password name=password2>
<Br />
*eMail: <input type=text name=email>
<Br />
<input type=submit name=submit value=Register>
";

$SECUREPASS = sha1($PASSWORD);

$QUERY = "INSERT INTO users (`username`, `password`, `email`, `ipaddress`, `joindate`) VALUES ('$USERNAME', '$SECUREPASS', '$EMAIL', '$IPADDRESS', '$JOINDATE');";
$RESULT = mysql_query($QUERY) or die(mysql_error());

?>


#2 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 29 June 2006 - 05:02 AM

[!--quoteo(post=389084:date=Jun 28 2006, 10:08 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ Jun 28 2006, 10:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
error messages i made display when the form first loads which shouldnt happen, also if the errors happen it still writes whats left to the databasE! i cant make any sense of it, can anyone help me out?

<?php

include('dbconnect.php');

$USERNAME = $_POST['username'];
$PASSWORD = $_POST['password'];
$PASSWORD2 = $_POST['password2'];
$EMAIL = $_POST['email'];

$IPADDRESS = $_SERVER['REMOTE_ADDR'];
$JOINDATE = date('m-d-Y');

if($USERNAME==NULL || $PASSWORD==NULL || $PASSWORD2==NULL || $EMAIL==NULL)
{
echo "ALL fields must be completed before continuing registration.<Br />";
}

if($PASSWORD!=$PASSWORD2)
{
echo "Both passwords must match in order to continue.<Br />";
}

if(strlen($USERNAME<4 || $USERNAME>16))
{
echo "Username must be between 4 and 16 characters.<Br />";
}

if(strlen($PASSWORD<4 || $PASSWORD>16))
{
echo "Password must be between 4 and 16 characters.<Br />";
}

if(strlen($EMAIL<4 || $PASSWORD>24))
{
echo "eMail must be between 4 and 24 characters.<Br />";
}

echo "
<form action=\"\" method=POST>
*Username: <input type=text name=username>
<Br />
*Password: <input type=password name=password>
<Br />
*Confirm Password: <input type=password name=password2>
<Br />
*eMail: <input type=text name=email>
<Br />
<input type=submit name=submit value=Register>
";

$SECUREPASS = sha1($PASSWORD);

$QUERY = "INSERT INTO users (`username`, `password`, `email`, `ipaddress`, `joindate`) VALUES ('$USERNAME', '$SECUREPASS', '$EMAIL', '$IPADDRESS', '$JOINDATE');";
$RESULT = mysql_query($QUERY) or die(mysql_error());

?>
[/quote]


theres no if under the post to database code it just tells it to post.... as long as you know ur checking script works try this

<?php



$USERNAME = $_POST['username'];
$PASSWORD = $_POST['password'];
$PASSWORD2 = $_POST['password2'];
$EMAIL = $_POST['email'];
$i=0;

$IPADDRESS = $_SERVER['REMOTE_ADDR'];
$JOINDATE = date('m-d-Y');

if($USERNAME==NULL || $PASSWORD==NULL || $PASSWORD2==NULL || $EMAIL==NULL)
{
echo "ALL fields must be completed before continuing registration.<Br />";
}else{
$i++;
}

if($PASSWORD!=$PASSWORD2)
{
echo "Both passwords must match in order to continue.<Br />";
}else{
$i++;
}

if(strlen($USERNAME<4 || $USERNAME>16))
{
echo "Username must be between 4 and 16 characters.<Br />";
}else{
$i++;
}

if(strlen($PASSWORD<4 || $PASSWORD>16))
{
echo "Password must be between 4 and 16 characters.<Br />";
}else{
$i++;
}

if(strlen($EMAIL<4 || $PASSWORD>24))
{
echo "eMail must be between 4 and 24 characters.<Br />";
}else{
$i++;
}

echo "
<form action=\"\" method=POST>
*Username: <input type=text name=username>
<Br />
*Password: <input type=password name=password>
<Br />
*Confirm Password: <input type=password name=password2>
<Br />
*eMail: <input type=text name=email>
<Br />
<input type=submit name=submit value=Register>
";

$SECUREPASS = sha1($PASSWORD);

if($i == 0){
include('dbconnect.php');
$QUERY = "INSERT INTO users (`username`, `password`, `email`, `ipaddress`, `joindate`) VALUES ('$USERNAME', '$SECUREPASS', '$EMAIL', '$IPADDRESS', '$JOINDATE');";
$RESULT = mysql_query($QUERY) or die(mysql_error());
}
?>

[!--quoteo(post=389111:date=Jun 28 2006, 11:57 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ Jun 28 2006, 11:57 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
theres no if under the post to database code it just tells it to post.... as long as you know ur checking script works try this, its simple but works and if you wanted to take it a step further use arrays.

<?php
$USERNAME = $_POST['username'];
$PASSWORD = $_POST['password'];
$PASSWORD2 = $_POST['password2'];
$EMAIL = $_POST['email'];
$i=0;

$IPADDRESS = $_SERVER['REMOTE_ADDR'];
$JOINDATE = date('m-d-Y');

if($USERNAME==NULL || $PASSWORD==NULL || $PASSWORD2==NULL || $EMAIL==NULL)
{
echo "ALL fields must be completed before continuing registration.<Br />";
}else{
$i++
}

if($PASSWORD!=$PASSWORD2)
{
echo "Both passwords must match in order to continue.<Br />";
}else{
$i++
}

if(strlen($USERNAME<4 || $USERNAME>16))
{
echo "Username must be between 4 and 16 characters.<Br />";
}else{
$i++
}

if(strlen($PASSWORD<4 || $PASSWORD>16))
{
echo "Password must be between 4 and 16 characters.<Br />";
}else{
$i++
}

if(strlen($EMAIL<4 || $PASSWORD>24))
{
echo "eMail must be between 4 and 24 characters.<Br />";
}else{
$i++
}

echo "
<form action=\"\" method=POST>
*Username: <input type=text name=username>
<Br />
*Password: <input type=password name=password>
<Br />
*Confirm Password: <input type=password name=password2>
<Br />
*eMail: <input type=text name=email>
<Br />
<input type=submit name=submit value=Register>
";

$SECUREPASS = sha1($PASSWORD);

if($i == 0){
include('dbconnect.php');
$QUERY = "INSERT INTO users (`username`, `password`, `email`, `ipaddress`, `joindate`) VALUES ('$USERNAME', '$SECUREPASS', '$EMAIL', '$IPADDRESS', '$JOINDATE');";
$RESULT = mysql_query($QUERY) or die(mysql_error());
}
?>
[/quote]

add the ";" at the end of each $i++ sorry i forgot it


[!--quoteo(post=389084:date=Jun 28 2006, 10:08 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ Jun 28 2006, 10:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
error messages i made display when the form first loads which shouldnt happen, also if the errors happen it still writes whats left to the databasE! i cant make any sense of it, can anyone help me out?

<?php

include('dbconnect.php');

$USERNAME = $_POST['username'];
$PASSWORD = $_POST['password'];
$PASSWORD2 = $_POST['password2'];
$EMAIL = $_POST['email'];

$IPADDRESS = $_SERVER['REMOTE_ADDR'];
$JOINDATE = date('m-d-Y');

if($USERNAME==NULL || $PASSWORD==NULL || $PASSWORD2==NULL || $EMAIL==NULL)
{
echo "ALL fields must be completed before continuing registration.<Br />";
}

if($PASSWORD!=$PASSWORD2)
{
echo "Both passwords must match in order to continue.<Br />";
}

if(strlen($USERNAME<4 || $USERNAME>16))
{
echo "Username must be between 4 and 16 characters.<Br />";
}

if(strlen($PASSWORD<4 || $PASSWORD>16))
{
echo "Password must be between 4 and 16 characters.<Br />";
}

if(strlen($EMAIL<4 || $PASSWORD>24))
{
echo "eMail must be between 4 and 24 characters.<Br />";
}

echo "
<form action=\"\" method=POST>
*Username: <input type=text name=username>
<Br />
*Password: <input type=password name=password>
<Br />
*Confirm Password: <input type=password name=password2>
<Br />
*eMail: <input type=text name=email>
<Br />
<input type=submit name=submit value=Register>
";

$SECUREPASS = sha1($PASSWORD);

$QUERY = "INSERT INTO users (`username`, `password`, `email`, `ipaddress`, `joindate`) VALUES ('$USERNAME', '$SECUREPASS', '$EMAIL', '$IPADDRESS', '$JOINDATE');";
$RESULT = mysql_query($QUERY) or die(mysql_error());

?>
[/quote]

"Syntax error" .. WHERE THE **** IS IT?!

#3 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 June 2006 - 03:33 PM

still displays all the errors to begin with

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 29 June 2006 - 04:04 PM

Local, here is what I suggest in terms of flow control...

if (!isset($_POST['submit']))  {// right here you're checking that the submit button was pressed, its value was 'submit'
// if it wasn't submitted then you'll just display the form, otherwise execute the data
// display form 
} else { // execute script here
$errors = array();
// from here on you try each piece of form data looking that it is what you want an example...
if (!isset($_POST['username']) or $_POST['username'] == '')
{
$error[] = 'username not set';
}
// ok now you've checked all the data, so check to see if any errors were set
if (count($errors) > 0) { // if yes, then display errors
foreach ($errors as $string) {
echo $string; // add whatever formatting you want
}
} else { // execute the data, submit it to the database
// mysql from here on out
}

Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users