我有一个带有 php 表单验证的 php 注册脚本。验证似乎工作正常,但它独立于 mysql 插入查询,因此无论表单输入是否正确,数据仍将沉入数据库。
<!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>
那是我的 register.php 包含 php 表单验证。
这是包含 mysql 查询的 check_register
有人请用主眼帮我找出问题
<?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>";
}
?>