Home > Database > Mysql Tutorial > body text

php-PHP菜鸟求解,insert命令总是无法插入mysql数据库

WBOY
Release: 2016-06-06 09:40:04
Original
1106 people have browsed it

mysqlphp数据库

这是connect.php文件

<code>@mysql_connect("localhost:3306","root","123456") or die("sql连接失败");@mysql_select_db("yhy") or die("yhy连接失败");//mysql_query("set names 'gb2312'");mysql_set_charset("gbk");</code>
Copy after login

?>

这是add.php文件
include("connect.php");//引入连接数据库模块
if(!empty($_POST['sub']))
{

$title=$_POST['title'];
$con=$_POST['con'];
$sql="insert into yhy100(id,title,dates,contents) values(null,'$title',now(),'$con')"."
";
mysql_query($sql);
if(mysql_query($sql))
{
echo "插入成功";
}
else
echo "插入失败";

<code>}   </code>
Copy after login

?>

标题
内容

初学PHP额,连接数据库没问题,但每次点“发表”就提示插入失败,总是无法把数据插入到数据库,这么一个小例程要把我搞死了,求各位大虾指教哇。。。。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!