Make Php+mysql Message Board

Source: Internet
Author: User

Create a database

CREATE TABLE ' message ' (' ID ' tinyint (1) NOT NULL auto_increment, ' user ' varchar (+) NOT null, ' title ' varchar NULL, ' content ' tinytext not null, ' lastdate ' date not NULL, PRIMARY KEY (' id ')) engine=innodb DEFAULT CHARSET=GBK AUT O_increment=1;


Creative a file to use as a linked database

<?php$conn = @mysql_connect ("localhost", "root", "") or Die ("Database link Error"), mysql_select_db ("BBS", $conn); mysql_query (" Set names ' GBK '); Use GBK Chinese code;? >


Create a file that submits a message to the database

<?phperror_reporting (E_all & ~e_notice), include ("conn.php"), if ($_post[' submit ') {echo $sql = "INSERT INTO Message (Id,user,title,content,lastdate) "." Value ("', ' $_post[user] ', ' $_post[title] ', ' $_post[content] ', now ())"; mysql_query ($sql); echo "published success";}? ><form action= "add.php" method= "POST" > Users: <input type= "text" size= "ten" name= "user" ><br> title:< Input type= "text" size= "name=" title ><br> contents: <textarea name= "Content" ></textarea><br ><input type= "Submit" name= "Submit" value= "Post message" ></form>

It is best not to use the second line error_reporting (E_all & ~e_notice);

Instead, modify the IF ($_post[' submit ') conditional statement to if (isset ($_post[' submit ')) && $_post[' Submit '])


Create a preview page

<?phpinclude ("conn.php");? ><table width=500 border= "0"  align= "center"  cellpadding= "5"  cellspacing= "1"  bgcolor= "#add3ef" >  <?php   $sql = "select * from message  Order by id desc ";   $query =mysql_query ($sql, $conn);  while  ($row =mysql _fetch_array ($query)) {  ?>  <tr bgcolor= "#eff3ff" >  <td> title: <?php echo  $row [' title '];? >  user:<?php echo  $row [' user '];? ></td>  </tr>  <tr bgcolor= "#ffffff" >  <td> content: <?php echo  $row [' content '];? ></td>  </tr>  <?php  }  print_r ($row);    ?>  </table> 

The label must be written in full















Related Article

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.