Registration page
inserting JS validation
<script type= "Text/javascript" >
Window.onload = function () {
var hid = document.getElementById ("id");
if (Hid.value! = "") {//when the user name already exists in the database, the user is prompted to register
Alert ("User name is registered");
}
}
</script>
HTML Form
The hidden field is used to obtain the ID value passed by the yanzheng.php, and if obtained, the user is registered .
<input type= "hidden" name= "UID" value= "<?php echo $_get[" id "]? $_get["id"]: "";?> "id=" id ">
create a form to submit data entered by the user
<form action= "yanzheng.php" method= "POST" >
information that is used to store user input
User name: <input type= "text" name= "id" ><br>
Password: <input type= "password" name= "Screct" ><br>
Confirm Password: <input type= "password" name= "Screct1" ><br>
used to submit the form
<input type= "Submit" value= "Registration" >
</form>
PHP forms and data Information validation
<?php
// set PHP code
Header ("Content-type:text/html;charset=utf-8");
define variable
$id =$_post["id"];
$screct =$_post["Screct"];
// Connect to database
$db = new mysqli ("localhost", "root", "", "Z_text");
Verify that the database is connected successfully
!mysqli_connect_error () or Die ("Connection Failed");
set Encoding
$db, query ("Set names UTF8");
add value to database
$sql = "SELECT * from user where name= ' $id '";
Execute qul code
$ret = $db, query ($sql);
convert result to array
$att = $ret-Fetch_all ();
Determine if registration information exists
if ($att ==false) {
// Add registration information to the database
$sql = "INSERT into user (Name,password) VALUES (' $id ', ' $screct ')";
// execute qul code
$ret = $db, query ($sql);
determine if validation is successful
if ($ret) {
verification Success then jump value check -in homepage
Header ("location:shouye.php");
}else{
return to the registration page if unsuccessful
Header ("location:zuce.php");
}
}else{
If the registration information already exists, return zece.php with the ID value
Header ("location:zuce.php?id=1");
}
?>
The problems encountered and their analysis
1.php page encoding Problem:
Header ("Content-type:text/html;charset=utf-8");
2. Data transmission problems:
Header ("Location: path? key = value"); (value is passed by get);
3. Common error
Notice:undefined Index: The variable is not found, or the variable is a null value
Solution: According to the error prompt to find the location, and then output error line to step through the troubleshooting
4. When using PHP to manipulate data, other than the results of the query results are Boolean values
5.php Transmit value receive problem
The value that PHP passes through can create a hidden field to accept
<input type= "hidden" name= "UID" value= "<?php echo $_get[" id "]? $_get["id"]: "";?> ">
The value passed by PHP can be used directly for the output receive.
Welcome: <?php Echo $uid?>
PHP Connection usage with database (sign in one)