The newbie encountered a small problem in the example of making a message board.-php Tutorial

Source: Internet
Author: User
Tags valid email address
The newbie encountered a small problem in the example of making a message board. could you please help me? I want to make a simple message board. I don't have a database. after all, I just learned it for two days ~
Two pages. one page is an HTML message board.
The PHP page is used to input HTML values and then pass in the PHP page to determine whether the passed values are null or whether the mailbox format is correct.
It is displayed directly if it is correct.
At present, I found that my judgment is not easy to use. I don't know what went wrong.


The code is as follows:

Html interface code:




Message




The PHP interface code is as follows:
$ Mst = $ _ POST ['mstit'];
If (isset ($ mst ))
{
Echo "Enter the message title ";
} Else {
Echo $ mst;
}
$ Msu = $ _ POST ['msuser'];
If (isset ($ msu )){
Echo "enter the user name of the message ";
Exit;
}
If (! Preg_match ("/^ [a-zA-Z] * $/", $ msu )){
Echo "this is not a valid user name, please use letters ";
} Else {
Echo $ msu;
}
$ Maem = $ _ POST ['maeme'];
If (isset ($ mean )){
Echo "enter your email address ";
Exit;
}
If (! Preg_match ("/([\ w \-] + \ @ [\ w \-] + \. [\ w \-] +)/", $ maem )){
Echo "this is not a valid email address ";
} Else {
Echo $ maem;
}
$ Comt = $ _ POST ['comment'];
If (isset ($ comt )){
Echo "Enter the message content ";
} Else {
Echo $ comt;
}
?>


Reply to discussion (solution)

If (isset ($ comt )){//! Isset
Echo "Enter the message content ";
} Else {
Echo $ comt;

If (isset ($ comt )){//! Isset
Echo "Enter the message content ";
} Else {
Echo $ comt;


What does it mean?

All the well-known controls except the unselected re-(single) button in the form will be submitted.
So you use
$ Mst = $ _ POST ['mstit'];
If (isset ($ mst ))
It is incorrect to determine whether name = mstit is null.
1. $ _ POST ['mstit'] always exists, no matter whether there is a value or not
2. a prompt is output only when it is empty. your business logic is reversed.

It can be modified in this way.

$ Mst = $ _ POST ['mstit']; if (empty ($ mst) {echo "Enter the message title" ;}else {echo $ mst ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.