代码哪儿错了,为什么在a.php中提交之后数据库依然为空?
a.php:<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/x...
a.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>测试</TITLE>
<body>
<form action="b.php" method="post">
<p>title:
<input type="text" name="title">
</p>
<p>content:
<input type="text" name="content">
</p>
<p>time1:
<input type="text" name="time">
</p>
<p>
<center><input type="submit" value="submit"></center>
</form>
</body>
</head>
</html>
b.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>测试</TITLE>
<body >
<?php
$conn=mysql_connect("127.0.0.1","root","sql1234") or die("不能连接到数据库服务器!可能是数据库服务器没有启动,或者用户名密
码有误!");
mysql_select_db("abc");
$title=$_POST[title];
$content=$_POST[content]; //读取了鼠标的X坐标
$time1=$_POST[time]; //读取了鼠标的y坐标
$sql = "insert into p (title,content,time)
values ('$title','$content','$time')";
echo "$sql";
$result = mysql_query($sql);//执行
?>
</body>
</head>
</html> 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>测试</TITLE>
<body>
<form action="b.php" method="post">
<p>title:
<input type="text" name="title">
</p>
<p>content:
<input type="text" name="content">
</p>
<p>time1:
<input type="text" name="time">
</p>
<p>
<center><input type="submit" value="submit"></center>
</form>
</body>
</head>
</html>
b.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>测试</TITLE>
<body >
<?php
$conn=mysql_connect("127.0.0.1","root","sql1234") or die("不能连接到数据库服务器!可能是数据库服务器没有启动,或者用户名密
码有误!");
mysql_select_db("abc");
$title=$_POST[title];
$content=$_POST[content]; //读取了鼠标的X坐标
$time1=$_POST[time]; //读取了鼠标的y坐标
$sql = "insert into p (title,content,time)
values ('$title','$content','$time')";
echo "$sql";
$result = mysql_query($sql);//执行
?>
</body>
</head>
</html> 展开
1个回答
推荐于2016-08-23
展开全部
<?php
$conn = mysql_connect('localhost', 'root', 'sql1234') or die(mysql_error());
mysql_select_db('abc') or die(mysql_error());
$title = $_POST['title'];
$content = $_POST['content']; //读取了鼠标的X坐标
$time1 = $_POST['time']; //读取了鼠标的y坐标
$sql = "insert into p (title,content,time) values ('{$title}','{$content}','{$time}')";
echo mysql_query($sql) ? 'ok' : mysql_error();
?>
编程要有个良好的习惯, 不是尽量的节省开发力气而不顾程序质量!
该用引号的就用上引号, 该用单引号的就别用双引号
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询