How to save data to a mysql database instance in php-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www.111cn. netTRxhtml1DTDxhtml1-transitional.dtd & quot; & gt; & lt; htmlxmlns & quot; www.w3.org script ec (2); script





Add data to mysql in the php tutorial.





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 ("invalid title, re-enter information"); history. back (); script ');
}
Else if ($ body = "" | strlen ($ body)> 2048)
{
Exit ('script alert ("empty too long, re-enter the information"); history. back (); script ');
}
Else
{
$ Time = time ();
$ Body = preg_replace ("/$ title/", "". $ title. "", $ body, 1 );
$ 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 ("saved successfully"); 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 (200) character set gb2312 default NULL,
'Keyword' varchar (60) 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;


This site original tutorial, reprinted with the source of http://www.111cn.net, otherwise it is necessary to study

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.