作者:小胖胖的夢2502895687 | 来源:互联网 | 2018-07-16 14:21
这是一款老外写的mysqlphp接受数据过来然后进行数据保存在mysql_real_escape_string(nl2br(strip_tags($_POST[comment])));我觉得写得我们有一点区别吧。
这是一款老外写的mysql php接受数据过来然后进行数据保存在mysql_real_escape_string(nl2br(strip_tags($_POST[\'comment\'])));我觉得写得我们有一点区别吧。
database config
*/
代码如下 |
|
$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 be a nice place to start customizing - the default user
// you 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(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;
--
-- dumping data for table `wave_comments`
--
insert into `wave_comments` values(1, 0, 'tutorialzine', 'this is a demo for a tutorialzine tutorial about creating a google wave-like history slider.
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 php, mysql, jquery and css教程. the slider was created with jquery ui. view the tutorial.', '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');