Jump to content

Archived

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

localhost

Registration Script

Recommended Posts

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?

[code]<?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());

?>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=389084:date=Jun 28 2006, 10:08 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ Jun 28 2006, 10:08 PM) [snapback]389084[/snapback][/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?

[code]<?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());

?>[/code]
[/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

[code]<?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());
}
?>[/code]

[!--quoteo(post=389111:date=Jun 28 2006, 11:57 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ Jun 28 2006, 11:57 PM) [snapback]389111[/snapback][/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.

[code]<?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());
}
?>[/code]
[/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) [snapback]389084[/snapback][/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?

[code]<?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());

?>[/code]
[/quote]

Share this post


Link to post
Share on other sites
Local, here is what I suggest in terms of flow control...

[code]
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
}
[/code]

Share this post


Link to post
Share on other sites

×

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.