PHP把数据写入数据库问题,能够连接,但是无法把数据写入数据库。
<?include("bbs.php");if($_POST['submit']){$sql="insertintoliuyanben(id,name,from,emai...
<?
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
mysql_query($sql);
if($sql)
{
print_r($sql);
}
?>
<script language="javascript">
function checkpost()
{
if(myform.user.value=="")
{
alert("请填写用户名");
myform.user.focus();
return false;
}
if(myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if(myform.content.value=="")
{
alert("内容不能为空");
myform.content.focus();
return false;
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>留言写入本</title>
<style>
body { font:12px Tahoma;margin:0px;text-align:center;background:#FFF;}
#header{ width:800; height:25; margin:20px auto; background:#F8A60E }
#body { width:800; height:400; margin:10px auto; background:#F8A60E }
#footer{ width:800; height:50; margin:20px auto 5px; background:#F8A60E}
</style>
</head>
<body>
<div id="header" ><font color="#333333" size="+2" face="黑体" >发表留言:</font> 留言总数:</div>
<div id="body">
<form action="l-xieru.php" method="post" name="myform" onSubmit="return checkpost();">
<table border="2">
<tr>
<td>用户:<td><input type="text" name="user"></td> <td>电子邮件:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>来自:</td> <td><input type="text" name="from"></td> <td>QQ</td><td><input type="text" name="qq"> </td>
</tr>
<tr> <td>标题:</td> <td><input type="text" name="title"></td></tr>
<tr><td>内容:</td><br/><td><textarea name="content" cols="35" rows="9"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="发表留言"></td></tr>
<tr><td><input type="reset" value="全部重填"></td></tr>
</table>
</form>
</div>
<div id="footer"> </div>
</body>
会追加分数的 展开
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
mysql_query($sql);
if($sql)
{
print_r($sql);
}
?>
<script language="javascript">
function checkpost()
{
if(myform.user.value=="")
{
alert("请填写用户名");
myform.user.focus();
return false;
}
if(myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if(myform.content.value=="")
{
alert("内容不能为空");
myform.content.focus();
return false;
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>留言写入本</title>
<style>
body { font:12px Tahoma;margin:0px;text-align:center;background:#FFF;}
#header{ width:800; height:25; margin:20px auto; background:#F8A60E }
#body { width:800; height:400; margin:10px auto; background:#F8A60E }
#footer{ width:800; height:50; margin:20px auto 5px; background:#F8A60E}
</style>
</head>
<body>
<div id="header" ><font color="#333333" size="+2" face="黑体" >发表留言:</font> 留言总数:</div>
<div id="body">
<form action="l-xieru.php" method="post" name="myform" onSubmit="return checkpost();">
<table border="2">
<tr>
<td>用户:<td><input type="text" name="user"></td> <td>电子邮件:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>来自:</td> <td><input type="text" name="from"></td> <td>QQ</td><td><input type="text" name="qq"> </td>
</tr>
<tr> <td>标题:</td> <td><input type="text" name="title"></td></tr>
<tr><td>内容:</td><br/><td><textarea name="content" cols="35" rows="9"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="发表留言"></td></tr>
<tr><td><input type="reset" value="全部重填"></td></tr>
</table>
</form>
</div>
<div id="footer"> </div>
</body>
会追加分数的 展开
展开全部
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
这句话有点错误
$sql = "insert into liuyanben
(`id`,`name`,`from`,`email`,`qq`,`title`,`content`,`lastdate`)
values
('','".$_POST['user']."','".$_POST['from']."','".
$_POST['email']."','".$_POST['qq']."','".
$_POST['title']."','".$_POST['content']."'now())";
你把SQL这样修改一下 如果还是不行按照下面的方法测试
调试方法修改
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
mysql_query($sql);
代码为
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
var_dump($sql);
exit;
mysql_query($sql);
查看输出结果的sql字符串
使用 SQL工具(例如phpmyadmin)调试该字符串
对照调试结果修改
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
这句话有点错误
$sql = "insert into liuyanben
(`id`,`name`,`from`,`email`,`qq`,`title`,`content`,`lastdate`)
values
('','".$_POST['user']."','".$_POST['from']."','".
$_POST['email']."','".$_POST['qq']."','".
$_POST['title']."','".$_POST['content']."'now())";
你把SQL这样修改一下 如果还是不行按照下面的方法测试
调试方法修改
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
mysql_query($sql);
代码为
include("bbs.php");
if($_POST['submit'])
{
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
}
var_dump($sql);
exit;
mysql_query($sql);
查看输出结果的sql字符串
使用 SQL工具(例如phpmyadmin)调试该字符串
对照调试结果修改
$sql="insert into liuyanben (id,name,from,email,qq,title,content,lastdate)"." values('','$_POST[user]','$_POST[from]','$_POST[email]','$_POST[qq]','$_POST[title]','$_POST[content]',now())";
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询