data verification
Cleaning space
The TRIM function will clear the space of the data head, and its syntax is:
TRIM ($ first_name);
Required field processing
In your database, some fields must be filled in. This corresponds to the corresponding field corresponding to the HTML form, does not allow empty out. Of course, the process of this inspection process can be handled by the client's JavaScript script, but since we are talking about PHP, you will also use PHP to handle it. The following code checks if the user's last name is entered:
IF (EREG (".", $ first_name) == 1)
{
Print ("last 201:");
Print ("$ first_name");
$ verify = "ok";
}
Else
{
Print (" error: b> Your respected name is not filled");
$ verify = "bad";
}
EREG mode identification function, used to determine if the specified string contains a certain substring. Its first parameter is to determine if the substrings contain, the second parameter specifies the string to search, usually a variable. The EREG function returns "0" (false), indicating matching failure, or "TRUE), indicates that the match is successful. Here, "." Is a modal formula, representing any characters. Such an expression EREG (".", $ First_NAME) == 1 means that at least one character is included in the variable $ first_name.
Check E-mail address
Use the following character constants as the first parameter of the EREG function, you can easily check the E-mail address:
"@": Must contain @
"^ @": Can't use @ head
"@. * ...": There must be characters in @ and.
"... *": There is at least two characters after it.
"": No space is allowed
By this parameter example, you can also design some other input verification.
Check if the username is unique
This action seems to be necessary:
MySQL_Connect (localhost, username, password);
MySQL_SELECT_DB (DBNAME);
$ results = mysql_query ("SELECT * from TableName
Where user_id = / '$ user_id /'
");
IF ($ row = mysql_fetch_array ($ result))
{
Print (" error: b> User Name ");
Print ("$ user_id");
Print (" b> is already occupied, please try again.");
Print ("
");
$ verify = "bad";
}
Else
{
PRINT ("User ID:");
Print ("$ user_id");
}
The idea of the code is very simple, read here, I believe it can't help you.
Check if the username is unique
This action seems to be necessary:
MySQL_Connect (localhost, username, password);
MySQL_SELECT_DB (DBNAME);
$ results = mysql_query ("SELECT * from TableName
Where user_id = / '$ user_id /'
");
IF ($ row = mysql_fetch_array ($ result))
{
Print (" error: b> User Name ");
Print ("$ user_id");
Print (" b> is already occupied, please try again.");
Print ("
");
$ verify = "bad";
}
Else
{
PRINT ("User ID:");
Print ("$ user_id");
}
The idea of the code is very simple, read here, I believe it can't help you.