php连接mysql数据库 插入数据 但是mysql依然为空??
conn.php代码<?php@mysql_connect("localhost:3306","root","")ordie("mysql连接失败");@mysql_se...
conn.php代码
<?php @mysql_connect("localhost:3306","root","")or die("mysql连接失败"); @mysql_select_db("php100")or die("db连接失败"); mysql_query("set names 'gbk'");?>
add.php代码
<?php include("conn.php");if(!empty($_POST['sub'])){ $title=$_POST['title']; $con=$_POST['con']; $sql="insert into news(id,title,dates,contents)values(null,'$title',now(),'$con')"; mysql_query($sql); echo "插入成功";}?>
<form action="add.php" method="post">标题<input type="text" name="title"><br>内容<textarea rows="5" cols="50" name="con"></textarea><br><input type="submit" name="sub" value="发表"></form> 展开
<?php @mysql_connect("localhost:3306","root","")or die("mysql连接失败"); @mysql_select_db("php100")or die("db连接失败"); mysql_query("set names 'gbk'");?>
add.php代码
<?php include("conn.php");if(!empty($_POST['sub'])){ $title=$_POST['title']; $con=$_POST['con']; $sql="insert into news(id,title,dates,contents)values(null,'$title',now(),'$con')"; mysql_query($sql); echo "插入成功";}?>
<form action="add.php" method="post">标题<input type="text" name="title"><br>内容<textarea rows="5" cols="50" name="con"></textarea><br><input type="submit" name="sub" value="发表"></form> 展开
2015-03-21
展开全部
把你的new表删除,然后运行下面的sql语句
CREATE TABLE IF NOT EXISTS `news` (
`id` int(11) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`dates` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`contents` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `news`
ADD PRIMARY KEY (`id`);
ALTER TABLE `news`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
运行后,数据效果图如下:
然后,conn.php代码
<?php
$Conn = mysql_connect('localhost', 'root', '') or die( '数据库服务器连接失败:' .mysql_error() );
mysql_query('set names utf8');
mysql_select_db('php100') or die('数据库连接失败' . mysql_error());
add.php
<?php
if ( !empty( $_POST['sub'] ) ) {
$title = $_POST['title'];
$con = $_POST['con'];
echo msyql_query("insert into new (title, contents) values ('{$title}', '{$con}')") ? '插入成功' : '插入失败:' .mysql_error();
}
?>
//下面的表单自己写
2015-03-21
展开全部
你先输出sql语句看看是什么,conn也写的有问题.百度搜 php MySQL类
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询