PHP MySQL Data Save instance

Source: Internet
Author: User
Tags php mysql

Database Config
*/

The code is as follows Copy Code

$db _host = ' localhost ';
$db _user = ' root ';
$db _pass = ';
$db _database = ';

$link = mysql_connect ($db _host, $db _user, $db _pass) or Die (' unable to establish a DB connection ');

mysql_select_db ($db _database, $link);
mysql_query ("Set names UTF8");


if (Empty ($_post[' comment ')) die ("0");
If there isn ' t a comment text, exit

$comment = mysql_real_escape_string (NL2BR (strip_tags ($_post[' comment ')));
$user = ' demo ';
This would is a nice place to start customizing-the Default User
Can integrate it to any site and show a different username.

$addon = ';
if ($_post[' parent ']) $addon = ', parent= '. (int) $_post[' parent '];

mysql_query ("INSERT into wave_comments set usr=". $user. "', comment= '". $comment. "", Dt=now () ". $addon);

if (Mysql_affected_rows ($link) ==1)
echo mysql_insert_id ($link);
If the insert was successful, echo the newly assigned ID
Else
echo ' 0 ';
?>

Sql

--
--Table structure for table ' wave_comments '
--

CREATE TABLE ' Wave_comments ' (
' id ' int (one) not NULL auto_increment,
' Parent ' int (one) not null default ' 0 ',
' usr ' varchar collate utf8_unicode_ci NOT NULL default ',
' Comment ' text collate utf8_unicode_ci NOT NULL,
' DT ' datetime NOT NULL default ' 0000-00-00 00:00:00 ',
Primary KEY (' ID '),
Key ' parent ' (' parent ', ' ID ')
) Engine=myisam default Charset=utf8 collate=utf8_unicode_ci;

--
--Dumping data for table ' wave_comments '
--

Insert INTO ' wave_comments ' values (1, 0, ' tutorialzine ', ' It's a demo for a tutorialzine tutorial about creating a Goog Le wave-like history slider.<br/><br/>rnto Get started, just drag the slider above, and this thread would be Reverted to a past state. ', ' 2009-10-24 03:58:08 ');
Insert INTO ' wave_comments ' values (2, 0, ' curious ', ' are HTML allowed in the comments? ', ' 2009-10-24 03:59:44 ');
Insert INTO ' wave_comments ' values (3, 2, ' tutorialzine ', ' Nope ', ' also ') messages in this demo are deleted every-hour to P Revent spamming. ', ' 2009-10-24 04:00:15 ');
Insert INTO ' wave_comments ' values (4, 1, ' tutorialzine ', ' In this tutorial we are using <b>php</b>, <b>m Ysql</b&gt, <b>jquery</b> and <b>css tutorial </b>. The slider is created with <b>jquery Ui</b>. <a href= "http://111cn.net/2009/10/google-wave-history-slider-jquery/" target= "_blank" >view the tutorial</ A>. ', ' 2009-10-24 04:01:34 ');
Insert INTO ' wave_comments ' values (5, 2, ' curious ', ' thanks! also I noticed "you can click, rather than drag the slide r.great! ', ' 2009-10-24 04:11:48 ');

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.