<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.111cn.net/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>php Tutorial Add data Save to MySQL tutorial data instance Tutorials </title>
<style type= "Text/css Tutorial" >
<!--
Body {
margin-left:0px;
margin-top:10px;
margin-right:0px;
margin-bottom:0px;
}
td{
padding:2px;
}
body,td,th {
font-size:12px;
}
-->
</style>
<body>
<table width= "98%" border= "0" align= "center" cellpadding= "0" cellspacing= "1" bgcolor= "#F2F2F2" >
<form id= "Form1" Name= "Form1" method= "Post" action= "" ><tr>
<TD width= "15%" height= "align=" "Center" bgcolor= "#FFFFFF" > title:</td>
<TD width= "85%" bgcolor= "#FFFFFF" >
<label>
<input type= "text" name= "title"/>
</label> </td>
</tr>
<tr>
<TD height= "align=" "Center" bgcolor= "#FFFFFF" > Keyword:</td>
<TD bgcolor= "#FFFFFF" ><label>
<input name= "keyword" type= "text" id= "keyword" size= "a"/>
</label></td>
</tr>
<tr>
<TD height= "align=" center "bgcolor=" #FFFFFF "> Description:</td>
<TD bgcolor= "#FFFFFF" ><label>
<textarea name= "desc" cols= "rows=" "4" id= "desc" ></textarea>
</label></td>
</tr>
<tr>
<TD height= "align=" "Center" bgcolor= "#FFFFFF" > Introduction:</td>
<TD bgcolor= "#FFFFFF" ><label>
<textarea name= "Body" cols= "rows=" 8 "></textarea>
</label></td>
</tr>
<tr>
<TD height= "align=" center "bgcolor=" #FFFFFF "> </td>
<TD bgcolor= "#FFFFFF" ><label>
<input type= "Submit" name= "Submit" value= "Save Data"/>
</label></td>
</tr>
</form>
</table>
<?php
if ($_post)
{
mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db (' fangke_cc ');
mysql_query ("Set names ' GBK '");
$title = Htmlspecialchars (isset ($_post[' title ')]? $_post[' title ']: ";
$keyword = Htmlspecialchars (isset ($_post[' keyword ')) $_post[' keyword ']: ');
$desc = Htmlspecialchars (isset ($_post[' desc ')) $_post[' desc ']: ');
$body = Htmlspecialchars (isset ($_post[' body ')), $_post[' body '];
if ($title = = "" | | strlen ($title) > 200)
{
Exit (' <script>alert ("title not valid, re-enter information"); History.back ();</script> ');
}
else if ($body = = "" | | Strlen ($body) >2048)
{
Exit (' <script>alert ("Empty too long, re-enter information"); History.back ();</script> ');
}
Else
{
$time = time ();
$body =preg_replace ("/$title/", "$sql = "INSERT into SU_ZT (title,description,keyword,body,datetimes) VALUES (' $title ', ' $desc ', ' $keyword ', ' $body ', ' $ Time ') ";
mysql_query ($sql) or Die (Mysql_error (). $sql);
Die (' <script>alert ("save Success"); location= "'. $_server[' Http_referer '"; </script> ');
}
}
?>
SU_ZT table Structure
CREATE TABLE IF not EXISTS ' Su_zt ' (
' ID ' int (8) not NULL auto_increment,
' title ' varchar character Set gb2312 default NULL,
' keyword ' varchar character set gb2312 default NULL,
' Description ' text character set gb2312,
' Body ' text character set gb2312,
' DateTimes ' int (4) Default NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=2;
</body>
Site original tutorial, reprinted annotated source Http://www.111cn.net, otherwise must investigate