我是HTML和PHP的新手,所以请帮忙。在表单中输入的值不会存储在数据库中。我已经检查了数据库连接并且正在连接。我不知道代码有什么问题。
<?php
include("con.php");
$msg="";
if(isset($_POST["sub_btn"])) {
$id_length=6;
$id=crypt(uniqid(rand(),1));
$id=strip_tags(stripslashes($id));
$id=str_replace(".","",$id);
$id=strrev(str_replace("/","",$id));
$id=substr($id,0,$id_length);
$userid=$id;
$fname=$_POST["fname"];
$lname=$_POST["lname"];
$street=$_POST["street"];
$city=$_POST["city"];
$pin=$_POST["pin"];
$mail=$_POST["mail"];
$phone=$_POST["phone"];
$password=$_POST["pwd"];
$passconf=$_POST["pwdc"];
$mail_check="SELECT mail FROM userdata WHERE mail='$mail'";
$res=mysqli_query($db,$mail_check);
$row=mysqli_fetch_array($res,MYSQLI_ASSOC);
if(mysqli_num_rows($res)==1) {
$msg= "This email is already registered. Please login or use another email ID.";
}
else if (empty($fname) ||empty($lname) ||empty($street) ||empty($city) ||empty($pin) ||empty($mail) ||empty($phone) ||empty($password) ||empty($passconf)) {
//Checks for any blank field.
$msg="Cannot leave the field blank!";
}
elseif($password!=$passconf) {
//Checks for matching password.
$msg= "Passwords don't match!";
}
else {
$query=mysqli_query($db,"INSERT INTO userdata(userid, fname, lname, street, city, pin, mail, phone, password) VALUES('$userid','$fname','$lname','$street','$city','$pin','$mail','$phone','$password')");
if($query) {
$msg= "Thank you! You are now registered.";
//Or give another link to redirect.
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Signup</title>
<link rel="stylesheet" type="text/css" href="signupcss.css">
<link rel="icon" href="pageicon.png">
</head>
<body style="background:#212934;">
<div class="search_box" style="background:#85A25B;">
<form name="signup" action="index.php" method="post">
<h1 style="text-align:center;">SIGNUP</h1>
<h6 style="margin-left:36px;" >The <span style="color:#D62F0B">*</span> indicates required field.</h6>
<hr class="fieldlen_long" style="text-align:center;">
<ul class="form_style">
<br><list><label>FULL NAME<span class="required"> *</span></label>
<input type="text" name="fname" class="fieldlen_split" placeholder="First Name" />
<input type="text" name="lname" class="fieldlen_split" placeholder="Last Name" /></list><br>
<list><label>ADDRESS</label></list>
<list><input type="text" name="street" class="fieldlen_long" placeholder="Street" /></list>
<list><input type="text" name="city" class="fieldlen_split" placeholder="City" />
<input type="text" name="pin" maxlength="6" placeholder="Pincode" /></list>
<br>
<list><label>EMAIL ID <span class="required"> *</span></label>
<input type="email" name="mail" class="fieldlen_mail" placeholder="Email ID" /></list>
<br>
<list><label>PHONE<span class="required"> *</span></label><input type="text" name="phone" maxlength="10" placeholder="Phone" /></list>
<br>
<list><label>PASSWORD<span class="required"> *</span></label><input type="password" name="pwd" class="field-divided" placeholder="Password"/> <input type="password" name="pwdc" class="field-divided" placeholder="Confirm Password"/></list>
<br>
<div class="submitbutton">
<list><input type="submit" name="sub_btn" value="SUBMIT" /></list></div>
</ul>
</form>
</div>