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