Sometimes a blank form is sent to the customer, because nothing is filled out directly. Oh, how bad.
Introduces 2 functions, Isset and empty. Isset returns True for the assigned variable, regardless of the value assigned, the empty string is also true;empty when the parameter inside is null is the return true;
The null value has null, ' ', 0,false.
This will not be able to respond when the user submits the empty item. Should be in the client with JS first to deal with, and then PHP processing, PHP as the last wall inspection.
If there is a problem with submitting something, use an if loop like this to judge it.
After judging, in case of error, but also to echo back a form to the customer refill.
Just use the HTML code.
<?php
if (Out_false) {
?>
<form action= "<?php echo $_server[php_self]?>" method= "POST" >
<input type= "text" name= "user" value= "<?php echo $user?>" >
<input type= "pasword" name= "password" value=<?php echo $password?>>
<input type= "Submit" value= "Submit"/>
</form>
<?php
}
?>
<?php?> is outside the HTML code, but the form part is still inside the if logic, and this thing $_server[php_self], you can refer to the URL of the form submitted by the foreground. If the form data is incorrectly filled in, return a form directly, and the returned form records what was previously filled. <?php Echo $password?> directly into the form with PHP code, but this time the form address URL is. PHP ends, be careful.
In addition, you can use Isset ($_post[' submit ') to determine whether the form is submitted, click Submit, there is a value to the Super global variable, isset is true.
In addition, we must make each row of the table unique in the database. This is what the primary key is. This is going to change the data table, can not directly drop table dropped ...
ALTER TABLE name add ID int NOT NULL auto_increment First,add primary KEY (ID)
The main idea is to add the Id,int type, cannot be empty, each time you add 1, put in the first column, add the primary key, (each table has only one primary key drop), so that each row of data is unique.
What do you do with the only primary key? Read it tomorrow and write again. Hey, want to combine exertion.
[head First Php&mysql] reading notes-feedback from the customer (fourth chapter)