php mysql数据保存实例
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-15 14:48:47 浏览: 评论:0
这是一款老外写的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");
- // if there isn't a comment text, exit
- $comment = mysql_real_escape_string(nl2br(strip_tags($_post['comment'])));//开源代码phpfensi.com
- $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.<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');
Tags: php mysql数据保存实例
- 上一篇:php 数据库内容以数组形式保存文件中
- 下一篇:php简单的伪原创程序
相关文章
- ·PHP 是什么?(2013-11-12)
- ·Php.ini文件位置在哪里 Php.ini文件找不到(2013-11-12)
- ·PHP 数据类型(2013-11-12)
- ·php 获取当前脚本的url(2013-11-12)
- ·php技术生成静态页面的实现(2013-11-13)
- ·缺陷月项目启动 披露PHP脚本语言漏洞(2013-11-13)
- ·在PHP中全面阻止SQL注入式攻击(2013-11-13)
- ·php生成随机密码的几种方法(2013-11-13)
- ·PHP中使用FCKeditor2.3.2配置(2013-11-13)
- ·如何使用PHP开发高效的WEB系统(2013-11-13)
- ·php:树形结构的算法(2013-11-13)
- ·php4和php5区别(2013-11-13)
- ·php数据库连接(2013-11-13)
- ·如何正确理解PHP的错误信息(2013-11-13)
- ·php页面漏洞分析及相关问题解决(2013-11-13)
- ·当在连接PHP时,抱怨一些数值没有定义参考?(2013-11-27)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)