PHP REGISTRATION Assistance

I have a php registration Script with a php form validation. The Validation seems to be working fine But it is independent of mysql insert query so whether the form input is correct or not the data will still be sink into the data base.[php]

Register Page
<?php include("include/header.php"); ?> <?php include("include/nav.php"); ?> <?php include("include/left_bar.php"); ?>
First Name:

<?php if (isset($_POST["submit"])&&(empty($fname))) { echo"
Please Your Frist Name Is Required
";}?> Last Name:

<?php if (isset($_POST["submit"])&&(empty($lname))) { echo"
Please Your Last Name Is Required
";}?> User Name:

<?php if (isset($_POST["submit"])&&(empty($username))) { echo"
Please Your User Name Is Required
";}?> Email:

<?php if (isset($_POST["submit"])&&(empty($email))) { echo"
Please Your Email Is Required
";}?> Password:

<?php if (isset($_POST["submit"])&&(empty($password))) { echo"
Please a Password Is Required
";}?> Phone:

<?php if (isset($_POST["submit"])&&(empty($phone))) { echo"
Please Your Number Is Required
";}?> Gender:

<?php if (isset($_POST["submit"])&&(empty($gender))) { echo"
Please Your Gender Is Required
";}?>
<?php include("include/right_bar.php"); ?> <?php include("include/footer.php"); ?>
[/php]

that is my register.php that contain the php form validation.

Here is check_register that contains the mysql query

Someone Please Use master eye and Spot the Problem for me

[php]<?php
$host=“localhost”;
$dbuser=“root”;
$dbpass="";
$db_name=“login”;
$db_table=“login”;
mysql_connect("$host","$dbuser","$dbpass")
or die(“Could Not Establish Connection”);
mysql_select_db("$db_name")or die(mysql_error());

$fname=$_POST[“fname”];
$lname=$_POST[“lname”];
$username=$_POST[“username”];
$email=$_POST[“email”];
$password=$_POST[“password”];
$phone=$_POST[“phone”];
$gender=$_POST[“gender”];
//validation of input in the form fieldS
include(“register.php”);

$submit=mysql_query(“INSERT INTO users(fname,lname,username,email,password,phone,gender)VALUES(’$fname’,’$lname’,’$username’,’$email’,’$password’,’$phone’,’$gender’)”) or die(“REGISTRATION NOT COMPLETED Thanks”);
if($submit==TRUE){
Echo"

";
}
?>[/php]

quick and easy i’d do this:

register.php:
[php]

Register Page
<?php include("include/header.php"); ?>
<!-- end header-->
<!-- nav-->
<?php include("include/nav.php"); ?>

<!-- end nav-->
<!-- left bar-->
<?php include("include/left_bar.php"); ?>
<!-- end left bar-->
<!-- content-->
<div id="content" align="left">
    <form method="post" action="check_register.php">
        First Name: <br><input type="text" name="fname" ><br>
        <?php if (isset($_POST["submit"])&&(empty($fname)))
        { echo"<center><em><div id='form'>Please Your Frist Name Is Required<br></div></em></center>";$failed = true;}?>
        Last Name: <br><input type="text" name="lname" ><br>
        <?php if (isset($_POST["submit"])&&(empty($lname)))
        { echo"<center><em><div id='form'>Please Your Last Name Is Required<br></div></em></center>";$failed = true;}?>
        User Name: <br><input type="text" name="username" ><br>
        <?php if (isset($_POST["submit"])&&(empty($username)))
        { echo"<center><em><div id='form'>Please Your User Name Is Required<br></div></em></center>";$failed = true;}?>
        Email:<br> <input type="email" name="email" ><br>
        <?php if (isset($_POST["submit"])&&(empty($email)))
        { echo"<center><em><div id='form'>Please Your Email Is Required<br></div></em></center>";$failed = true;}?>
        Password: <br><input type="Password" name="password" ><br>
        <?php if (isset($_POST["submit"])&&(empty($password)))
        { echo"<center><em><div id='form'>Please a Password Is Required<br></div></em></center>";$failed = true;}?>
        Phone: <br><input type="tel" name="phone" ><br>
        <?php if (isset($_POST["submit"])&&(empty($phone)))
        { echo"<center><em><div id='form'>Please Your Number Is Required<br></div></em></center>";$failed = true;}?>
        Gender: <br><input type="text" name="gender" ><br>
        <?php if (isset($_POST["submit"])&&(empty($gender)))
        { echo"<center><em><div id='form'>Please Your Gender Is Required<br></div></em></center>";$failed = true;}?>
        <input type="submit" name="submit" value="Register">
    </form>
</div>
<!-- end content-->
<!-- right bar-->
<?php include("include/right_bar.php"); ?>
<!-- end right bar-->

<!-- footer-->
<?php include("include/footer.php"); ?>
[/php]

check_register.php:
[php]<?php
$host=“localhost”;
$dbuser=“root”;
$dbpass="";
$db_name=“login”;
$db_table=“login”;
mysql_connect("$host","$dbuser","$dbpass")
or die(“Could Not Establish Connection”);
mysql_select_db("$db_name")or die(mysql_error());

$fname=$_POST[“fname”];
$lname=$_POST[“lname”];
$username=$_POST[“username”];
$email=$_POST[“email”];
$password=$_POST[“password”];
$phone=$_POST[“phone”];
$gender=$_POST[“gender”];
//validation of input in the form fieldS
$failed = false;
include(“register.php”);
if ($failed == false) {
$submit=mysql_query(“INSERT INTO users(fname,lname,username,email,password,phone,gender)VALUES(’$fname’,’$lname’,’$username’,’$email’,’$password’,’$phone’,’$gender’)”) or die(“REGISTRATION NOT COMPLETED Thanks”);
if($submit==TRUE){
Echo"

";
}} else {
// do nothing if it fails. it should have already loaded the form to correct.
}
?>[/php]

all it does is create a variable $failed. if any of the validation checks cause an error to display it is marked as failed, if it is marked as failed it does not do the db insert.

Thanks Man You Are Good.

Sponsor our Newsletter | Privacy Policy | Terms of Service