FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Stopping rest of script if certain thing happens...





ncwdavid
Hey, I am trying to make a simple registration script and I am stuck. Here is my "Signup.html"
Code:

<?php
include('config.php');

<html>
<head>
<title>$site_name Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h1 align="center">$site_name</h1>
<form action="register.php" method="post">
<p>Please fill in the form below to register:</p>
<p><b>First Name:</b><br><input type="text" name="first_name"></p>
<p><b>Last Name:</b><br><input type="text" name="last_name"></p>
<p><b>Username:</b><br><input type="text" name="username"></p>
<p><b>Email Address:<b><br><input type="text" name="email_address"></p>
<p><b>Password:</b><br><input type="password" name="password"></p>
<p><b>Confirm Password:</b><br><input type="password" name="confirm_password"></p>
<p><b><input type="submit" value="Register"></b></p>
</form>
</body>
</html>
?>


Here is my "register.php" which the form is sent to:
Code:

<?php
include('config.php');
include('db.php');

/*Define variables using the post method*/
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$email_address = $_POST['email_address'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];

/*Quick password check*/
$password_check = ($password==$confirm_password);

/*Check if the fields were all entered*/
if( (!$first_name)||(!$last_name)||(!$username)||(!$email_address)||(!$password)||(!$confirm_password) ){

echo "The following errors occurred while trying to process your information:<br>";

if(!$first_name){
echo "First Name is a required field. Please go back and fill it in.<br>";
}

if(!$last_name){
echo "Last Name is a required field. Please go back and fill it in.<br>";
}

if(!$username){
echo "Username is a required field. Please go back and fill it in.<br>";
}

if(!$email_address){
echo "Email Address is a required field. Please go back and fill it in.<br>";
}

if(!$password){
echo "Password is a required field. Please go back and fill it in.<br>";
}

if(!$confirm_password){
echo "Confirm Password is a required field. Please go back and fill it in.<br>";
}

if($password_check==false){
echo "Passwords do not match. Please go back and fix it.<br>";
}
##############################
#THIS IS WHERE MY PROBLEM IS!#
##############################
}

/*Check if username or email already exist in the database*/
$sql_username_check= mysql_query("SELECT * FROM members WHERE username='$username'");
$sql_email_check=mysql_query("SELECT * FROM members WHERE email_address='$email_address'");

$username_check=mysql_num_rows($sql_username_check);
$email_check=mysql_num_rows($sql_email_check);


Now here is my problem. Look at the register.php script above.(Iknow its not finished) If you look towards the end of it you will see "THIS IS WHERE THE PROBLEM ID!" with loads of "#" symbols around it.

I obviously want the rest of the script to stop when a bit of info was not entered in the form. At that area becuase it is at the end of the curly brackets and it closes the if statements I want to some how stop the rest of the script from continuing if there is something missing in the form or if the passwords dont match but if they do the rest of the script continues. I was thinking of putting exit(); but I am not too sure exactly what it does.

Any ideas?
hexkid
ncwdavid wrote:
I obviously want the rest of the script to stop when a bit of info was not entered in the form. At that area becuase it is at the end of the curly brackets and it closes the if statements I want to some how stop the rest of the script from continuing if there is something missing in the form or if the passwords dont match but if they do the rest of the script continues. I was thinking of putting exit(); but I am not too sure exactly what it does.

Any ideas?


Yes, exit() is a useful option.
Code:
// ...
##############################
#THIS IS WHERE MY PROBLEM IS!#
##############################
exit('</body></html>'); // or exit(0);
}
// ...
AftershockVibe
You could use die() which terminates the script there and then.

A more elegant solution is just to use IF{}...ELSE{} or CASE to ensure that if an error state is reached that code is inaccessible.
ncwdavid
Whats the CASE thing your talkin about?
Related topics
Google's Search engine and its lies
Windows update problem..
Upload changing my files
Stopping the script without forcing the page to quit loading
Iframe issues - Need help please.
Has Anyone Heard of This?
Film Making - Anybody got tips?
making a site but I need help I am new to php and Runy scrip
Is there a Python Hello World using Apache?
Philosophy Essays & Philosophy Texts
Remember when....
Getting a tooltip popup to work with a hotspot in dreamweavr
class not registerd in explorer.exe, a pain in the back
25 Myths About Christianity
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.