In the previous blog on how to build a HTML5 on the SAE platform E-Invitation website, received a lot of feedback, there are many people to send the blessing of the wedding, thank you very much!
Web development from the Zero learning, recording their own learning process, a variety of front-end great gods can bypass the onlookers
Big marriage will come, a lot of things, and today finally drive themselves to the last remaining content to supplement
A brief introduction to the function of adding a message board to the E-invitation, using the PHP scripting language and MySQL database, can save a lot of deployment and maintenance work under Sina's SAE platform.
In the SAE Personal project management interface, click "Manage MySQL" from the MySQL page to access the MySQL database management interface provided by SAE,
With a little database knowledge, in the visual interface to add table, field planning, the same is online maintenance, very simple and convenient
Create a new "tb_message" table, to save the message record, the field contains the name, content, message time, whether to allow viewing, etc.
Then use the SAE editor in code management to add a message board interface to the home page of the E-invitation.
<articleclass= "container box style3"> <Header> <H1>Blessing</H1> <P>You can send us a message by following</P> </Header> <formMethod= "POST"Action= "add.php"> <Divclass= "Row Half"> <Divclass= "6u"><inputtype= "text"class= "text"name= "Name"placeholder= "Name" /></Div> </Div> <Divclass= "Row Half"> <Divclass= "12u"> <textareaname= "message"placeholder= "Message"></textarea> </Div> </Div> <Divclass= "Row"> <Divclass= "12u"> <ulclass= "Actions"> <Li><inputname= "Mysubmit"type= "Submit"value= " Take a word" /></Li> </ul> </Div> </Div> </form> </article>
Here is a form <form> to submit the message text, the server add.php script to handle the "request" with the message
Add.php source code is as follows, some of which is to obtain the client IP address of the request, to record the message IP
<?PHPinclude("conn.php");if($_post[' Mysubmit ']){ if(getenv("Http_client_ip")) $ip=getenv("Http_client_ip"); Else if(getenv("Http_x_forwarded_for")) $ip=getenv("Http_x_forwarded_for"); Else if(getenv("REMOTE_ADDR")) $ip=getenv("REMOTE_ADDR"); Else $ip= "Unknow"; $sql= "INSERT into Tb_message (no,name,messagetime,content,messageip,memo,isshow)". "Values (' ', '$_post[Name] ', now (), '$_post[Message] ', '$ip', ', ' 1 ') '; mysql_query($sql); Echo"The message was successful!"; }Else{ Echo"Error!"; } ?> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
The database connection coon.php code is as follows, the connection string is the fixed notation used by the MySQL database under SAE, APP_LOVEWITHLMJ is the database name
<? PHP $conn mysql_connect die ("Connection error"); mysql_select_db ("APP_LOVEWITHLMJ",$conn); mysql_query ("Set names ' Utf-8 '");? >
Remember to specify the UTF-8 encoding, otherwise the Chinese will appear garbled situation
This in the E-mail Invitation page after the message through the button to send a request, "message success" reply that the message was successful
If you want to add the view message function to the E-invitation,
class= "container box style3" > <header> header> <form method= "POST" action= "list.php" > class= "Row" > Class = "12u" > class= "Actions" > <li><input type= "Submit" value= "See what Everyone says"/> </li> </ul> </div> </div> </form> </article>
After sending a view message request, the service side "list.php" to handle this request, for the time reason, for the display message page is not decorated in HTML language, directly display the PHP query database after the form
<?PHPinclude("conn.php"); ?> <table width=500 border= "0" align= "center" cellpadding= "5" cellspacing= "1" bgcolor= "#cccccc" > <?PHP$sql= "SELECT * from Tb_message where isshow= ' 1 ' ORDER by Messagetime DESC"; $query=mysql_query($sql); while($row=Mysql_fetch_array($query)){ ?> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> <tr bgcolor=" #eeeeee "> <td> message Time: <?phpEcho $row[Messagetime];? ></td> </tr> <tr bgcolor= "#eeeeee" > <td> <?phpEcho $row[Name];? >: <?phpEcho $row[Content];? > </td> </tr> <?php}?> </table>
Such a message board with the function of the HTML5 electronic photo album is basically completed, in the Novice web development on the road, we exchange better suggestions and ideas
Web development from zero single row two: in the home-made electronic invitation to add Message board function, Sae+php+mysql