Jump to content

Easy Form Check... HELP!


Snooble

Recommended Posts

Hello everyone... I'm almost there.

 

I have 2 pages... one shows the register form, one is the check form.

 

I want to have 2 pages... not one...

 

heres the checkregister.php page

 

<?php
$errors = array();
if (empty($_POST['username']))
{
     $errors[] = 'Please supply a username';
}
if (empty($_POST['password']) || strlen($_POST['password']) < 6)
{
     $errors[] = 'You entered an invalid password';
}
if (empty($_POST['email']) || strpos($_POST['email'], '@') === false)
{
     $errors[] = 'You entered an invalid email';
}

$check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1";
$checkresult = mysql_query($check);

if (mysql_num_rows($checkresult) != 0)
{
     $errors[] = 'You entered a taken username';
}

$check2 = "SELECT * FROM wmusers where email='".$_POST['email']."' LIMIT 1";
$checkresult2 = mysql_query($check2);

if (mysql_num_rows($checkresult2) != 0)
{
     $errors[] = 'You entered a taken email';
}
$_SESSION['errors'] = $errors[];
if (count($errors))
{
     header("Location: register.php");
     exit;
}
else
{
     $sql = "INSERT INTO wmusers VALUES ('0', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0')";
     mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 
}
?>

 

I need it to send the errors back to register.php how will i save them and output them on register.php... until they're all correct then it continues to the complete.

 

Make sense? at the moment i cant get it to output the data to the first page when it header's.

 

Thanks

 

Snooble

Link to comment
Share on other sites

<?php
$errors = array();
if (empty($_POST['username']))
{
     $errors[] = 'Please supply a username';
}
if (empty($_POST['password']) || strlen($_POST['password']) < 6)
{
     $errors[] = 'You entered an invalid password';
}
if (empty($_POST['email']) || strpos($_POST['email'], '@') === false)
{
     $errors[] = 'You entered an invalid email';
}

$check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1";
$checkresult = mysql_query($check);

if (mysql_num_rows($checkresult) != 0)
{
     $errors[] = 'You entered a taken username';
}

$check2 = "SELECT * FROM wmusers where email='".$_POST['email']."' LIMIT 1";
$checkresult2 = mysql_query($check2);

if (mysql_num_rows($checkresult2) != 0)
{
     $errors[] = 'You entered a taken email';
}
if (count($errors))
{
     header("Location: register.php");
     exit;
}
else
{
     $sql = "INSERT INTO wmusers VALUES ('0', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0')";
     mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 
}
?>

 

EDIT I need to know how to echo out the array of errors

 

Snooble

Link to comment
Share on other sites

To pass variables to another page, include the page rather than redirect to another page.  For example:

 

 

include ('register.php')

die; //makes the current pages script stop, when the register is included

 

Now in the register.php page you can use the $error variables. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.