Jump to content

PHP REGISTRATION PROBLEM


Go to solution Solved by sasa,

Recommended Posts

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 wether the form input is correct or not the data will still be sink into the data base.

<!DOCTYPE html>
<html lang="en">
<head>
<meta content="en-us" http-equiv="Content-Language">
<link rel="stylesheet" href="style.css" type="text/css" media="all">
<title>
Register Page 
</title>
</head>
<body>
<div id="wrapper">
<!--header-->
<?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>";}?>
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>";}?>
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>";}?>
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>";}?>
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>";}?>
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>";}?>
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>";}?>
<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"); ?>
</div>
<!-- end footer-->
</body>
</html>

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
$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"<div style='background:yellow;'><script>alert('YOU HAVE SUCESSFULLY REGISTERED PLEASE LOGIN WITH YOUR USERNAME AND PASSWORD');</script></div>";
} 
?>
Edited by IlaminiAyebatonyeDagogo
Link to comment
https://forums.phpfreaks.com/topic/283467-php-registration-problem/
Share on other sites

 

But it is independent of mysql insert query so wether the form input is correct or not the data will still be sink into the data base.

Because you do not have any logic in your code to stop the script from running the insert query if the form fails your validation tests

Edited by Ch0cu3r
  • Solution

in line 21 define new variable for checkin is form valid

<?php include("include/left_bar.php"); $chk = TRUE; ?>

in line 27 - 28 add

<?php if (isset($_POST["submit"])&&(empty($fname)))
{ echo"<center><em><div id='form'>Please Your Frist Name Is Required<br></div></em></center>"; $chk = FALSE;}?>

same for another fields

and in line 21 of 2nd file add

if($chk) $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");

use isset() or !empty  ;D

<?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");
 if (isset($fname) && isset($lname) && isset($username) && isset($email) && isset($password)&& isset($phone) && $isset($gender) ){
$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"<div style='background:yellow;'><script>alert('YOU HAVE SUCESSFULLY REGISTERED PLEASE LOGIN WITH YOUR USERNAME AND PASSWORD');</script></div>";
} 
?>

this should work...

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.