php断开数据库时出错
费话不说代码如下;
<?php
$conn = mysql_connect("localhost","root","123456") or die("数据库链接失败".mysql_error());
if($conn) {
echo "数据库链接成功"."<br>";
}
$db_select=mysql_select_db("mydatabases",$conn) or die("数据库访问错误".mysql_error());
if($db_select) {
echo "数据库选择成功";
}
mysql_query("set names gb2312");
$title=$_POST[title];
$content=$_POST[content];
$createtime=date("Y-m-d H:i:s");
$sql=mysql_query("insert into tb_news(title,content,cteratetime)values('$title','$content','$createtime')");
if($sql) {
echo "<script>alert('添加成功');</script>";
} else {
echo mysql_error();
exit;
}
mysql_free_result($sql);
mysql_close($conn);
?>
出错结果如下;
数据库链接成功
数据库选择成功
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\myphp\admin_new.php on line 23
大家帮忙看下,这是哪里出错了。。郁闷!!看了N久也没有看出个东来。数据添加成功了!!!