Jump to content

Script does not end if there arre errors


eschuppe

Recommended Posts

Hey everyone,

 

I'm was editing my register script to change the errors. Now all the errors appear, however, now it doesn't stop.  Using exit(); doesnt seem to do much either. I would use echo or header but I want the script to display on the same page as the form if there is an error.

<meta name="generator" content="Namo WebEditor(Trial)">

<?php
session_start();


include ('dbc.php');


if ($_POST['Submit'] == 'Register')
{
if (strlen($_POST['full_name']) < 1)
   {
   $message .= '<p>Incorrect email, please enter valid email address.</p>';
    }
   if (strlen($_POST['email']) < 5)
   {
   $message .= '<p>Incorrect email, please enter valid email address.</p>';
    }
   if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
{
    $message .= '<p>Password does not match or empty.</p>';

}
if (strlen($_POST['user_idnum']) < 4)
    {
        $message .= '<p>Incorrect ID number. Please enter a valid ID number.</p>';
    }
if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
{
     $message .= '<p>Invalid code entered. Please enter the correct code as shown in the Image.</p>';
  		}
$rs_duplicates_id = mysql_query("SELECT id FROM users WHERE user_idnum='$_POST[user_idnum]'");
$duplicates_id = mysql_num_rows($rs_duplicates_id);

if ($duplicates_id > 0)
{
    $message .= '<p>Student ID already exists, Try Again.</p>';
}

if ($_POST['email'] && $_POST['pass2'] && $_POST['user_idnum'] && $_POST['full_name'])
$md5pass = md5($_POST['pass2']);
$activ_code = rand(1000,9999);
mysql_query("INSERT INTO users
              (`user_email`,`user_pwd`,`user_idnum`,`joined`,`activation_code`,`full_name`)
			  VALUES
			  ('$_POST[email]','$md5pass','$_POST[user_idnum]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error());

unset($_SESSION['ckey']);
echo("Registration Successful! An activation code has been sent to your email address with an activation link...");
  mysql_close(); // Close the database
}

       	if (isset($message)) {
       echo '<font color="red">'.$message.'</font>';
       }
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<form name="form1" method="post" action="register.php" style="padding:5px;">
        <p><br>
          Name:
          <input name="full_name" type="text" id="full_name">
          </p>
        <p>Email:
          <input name="email" type="text" id="email">
          </p>
        <p>Password:
          <input name="pass1" type="password" id="pass1">
          Atleast 5 characters</p>
        <p>Retype Password:
          <input name="pass2" type="password" id="pass2">
        </p>
        <p>
        ID Number:
         <input name="user_idnum" type="text" id="user_idnum">
         </p>
        <p>
          <input name="user_code" type="text" size="10">
          <img src="pngimg.php" align="middle">  </p>
        <p align="center">
          <input type="submit" name="Submit" value="Register">
        </p>
      </form>
<div align="left"></div>
</body>
</html>

 

move this part...

<?php
       	if (isset($message)) {
       echo '<font color="red">'.$message.'</font>';
       }

to before...

<?php
if ($_POST['email'] && $_POST['pass2'] && $_POST['user_idnum'] && $_POST['full_name'])

 

and add the die(); to it...

<?php
       	if (isset($message)) {
       echo '<font color="red">'.$message.'</font>';
       die();
       }

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.