php为什么在表单中插入数据会失败
代码如下:全部内容都放在test.php中我在表单输入内容显示为)——('5','5','5','5')bool(false)数据记录插入失败<?php$username...
代码如下:
全部内容都放在test.php中
我在表单输入内容显示为)——('5 ','5 ','5 ','5 ')bool(false) 数据记录插入失败
<?php
$username =$_POST['username'];
$pwd =$_POST['pwd'];
$repeat_pwd =$_POST['repeat_pwd'];
$name =$_POST['name'];
$email =$_POST['email'];
if(!empty($username)){
$db = @new mysqli("localhost","root","8682708","test");
if(mysqli_connect_errno()){
echo "数据库连接失败";
echo mysqli_connect_error();
exit();
}
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES()";
$sql = "('$username ','$pwd ','$name ','$email ')";
echo $sql;
$rs = $db->query($sql);
var_dump($rs);
if(!$rs){
$db->close();
echo '数据记录插入失败';
exit();
}
echo "<font color='red' size='5'>zhuce chenggong</font><br/>";
$db->close();
}
?>
<html>
<head>
<meta http-equiv="content-type content=""text/html;charset=utf-8">
<title>Register </title>
</head>
<body>
<?php
if(!empty($username)){
echo "您填入的信息是:<br>\n";
echo "用户名: $username<br>\n";
echo "密码:$pwd<br>\n";
echo "重复密码:$repeat_pwd<br>\n";
echo "姓名:$name<br>\n";
echo "email:$email<br>\n";
}
?>
<form name="frmRegister" method="post"action="test.php">
<table width="330" border="0" align="center" cellpadding=5 bgcolor="#ffff">
<tr>
<td width=40%>用户名</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>密码</td>
<td><input name="pwd" type="password" id="pwd"></td>
</tr>
<tr>
<td>重复密码</td>
<td><input name="repeat_pwd" type="password" id="repeat_pwd"></td>
</tr>
<tr>
<td>姓名</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html> 展开
全部内容都放在test.php中
我在表单输入内容显示为)——('5 ','5 ','5 ','5 ')bool(false) 数据记录插入失败
<?php
$username =$_POST['username'];
$pwd =$_POST['pwd'];
$repeat_pwd =$_POST['repeat_pwd'];
$name =$_POST['name'];
$email =$_POST['email'];
if(!empty($username)){
$db = @new mysqli("localhost","root","8682708","test");
if(mysqli_connect_errno()){
echo "数据库连接失败";
echo mysqli_connect_error();
exit();
}
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES()";
$sql = "('$username ','$pwd ','$name ','$email ')";
echo $sql;
$rs = $db->query($sql);
var_dump($rs);
if(!$rs){
$db->close();
echo '数据记录插入失败';
exit();
}
echo "<font color='red' size='5'>zhuce chenggong</font><br/>";
$db->close();
}
?>
<html>
<head>
<meta http-equiv="content-type content=""text/html;charset=utf-8">
<title>Register </title>
</head>
<body>
<?php
if(!empty($username)){
echo "您填入的信息是:<br>\n";
echo "用户名: $username<br>\n";
echo "密码:$pwd<br>\n";
echo "重复密码:$repeat_pwd<br>\n";
echo "姓名:$name<br>\n";
echo "email:$email<br>\n";
}
?>
<form name="frmRegister" method="post"action="test.php">
<table width="330" border="0" align="center" cellpadding=5 bgcolor="#ffff">
<tr>
<td width=40%>用户名</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>密码</td>
<td><input name="pwd" type="password" id="pwd"></td>
</tr>
<tr>
<td>重复密码</td>
<td><input name="repeat_pwd" type="password" id="repeat_pwd"></td>
</tr>
<tr>
<td>姓名</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html> 展开
4个回答
展开全部
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES()";
$sql = "('$username ','$pwd ','$name ','$email ')";
这一部分错了吧。应该是这样、
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES";
$sql. = "('$username ','$pwd ','$name ','$email ')";
第二个sql是$sql.不要忘记后面还有一个点,表示和上面的sql语句链接起来,因为你下面是和上面链接起来的,所以第一个$sql后面values后面就不用加()括号了。
$sql = "('$username ','$pwd ','$name ','$email ')";
这一部分错了吧。应该是这样、
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES";
$sql. = "('$username ','$pwd ','$name ','$email ')";
第二个sql是$sql.不要忘记后面还有一个点,表示和上面的sql语句链接起来,因为你下面是和上面链接起来的,所以第一个$sql后面values后面就不用加()括号了。
展开全部
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES()";
$sql = "('$username ','$pwd ','$name ','$email ')";
sql语句写错!
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES('aa','bb','cc','dd')";
$sql = "('$username ','$pwd ','$name ','$email ')";
sql语句写错!
$sql = "INSERT INTO t_user (f_username, f_password, f_name,f_email)VALUES('aa','bb','cc','dd')";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你应该在按钮上边写一个隐藏域,value的值就是表单的值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
输出sql语句在phpmyadmin中执行一下,看看报什么错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询