这是一款老外写的mysql php接受数据过来然后进行数据保存在mysql_real_escape_string(nl2br(strip_tags($_POST[\'comment\'])));我觉得写得和我们有一点区别吧,代码如下:
database config.php代码如下:
- $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(emptyempty($_post['comment'])) die("0");
-
-
- $comment = mysql_real_escape_string(nl2br(strip_tags($_post['comment'])));
- $user='demo';
-
-
-
- $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);
-
- else
- echo '0';
sql数据库文件如下:
-
-
-
-
- create table `wave_comments` (
- `id` int(11) not null auto_increment,
- `parent` int(11) not null default '0',
- `usr` varchar(16) 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;
-
-
-
-
-
- insert into `wave_comments` values(1, 0, 'tutorialzine', 'this is a demo for a tutorialzine tutorial about creating a google wave-like history slider.<br /><br />rnto get started, just drag the slider above, and this thread will be reverted to a past state.', '2009-10-24 03:58:08');
- insert into `wave_comments` values(2, 0, 'curious', 'is html allowed in the comments?', '2009-10-24 03:59:44');
- insert into `wave_comments` values(3, 2, 'tutorialzine', 'nope. also the messages in this demo are deleted every hour to prevent 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>mysql</b>, <b>jquery</b> and <b>css教程</b>. the slider was 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 that you can click, rather than drag the slider.great!', '2009-10-24 04:11:48');
|