通过die和mysql_error语句调试PHP SQL错误

一 代码

<!--处理文件代码-->
<?php 
	$conn=mysql_connect('localhost','root','root') or die("与服务器连接失败!");
  	mysql_select_db('db_database22',$conn) or die("没有找到数据库!");
  	if($_POST[Submit]=="提交"){
		$admin=$_POST[admin];				//获取提交的用户名
		$pass=$_POST[pass];					//获取提交的密码
		$dates=date("Y-m-d H:i:s");			//定义当前时间		
		$query="insert into user (admin,password,dates) values('$admin','$pass','$dates')";		//编写添加语句
		$result=mysql_query($query,$conn) or die(mysql_error()); 								//执行添加语句,并返回错误信息
	    if($result){
		   	echo "<script>alert('添加成功!'); window.location.href='index.php';</script>";
		}else{ 
			echo "添加失败!!"; 
		}    
	}
?>
<!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>SQL语句错误</title>
</head>
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
<body>
<!--表单提交页,设置的表单元素-->
<form name="form1" method="post" action="index.php">
<table width="240" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FF0000">
  <tr>
    <td width="80" align="right" bgcolor="#FFFFFF"><span class="STYLE1">管理员:</span></td>
    <td width="147" bgcolor="#FFFFFF"><input name="admin" type="text" id="admin" size="20"></td>
  </tr>
  <tr>
    <td align="right" bgcolor="#FFFFFF"><span class="STYLE1">密码:</span></td>
    <td bgcolor="#FFFFFF"><input name="pass" type="password" id="pass" size="20"></td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="提交"></td>
  </tr>
</table>
</form>
</body>
</html>
二 运行结果
Unknown column 'password' in 'field list'

猜你喜欢

转载自cakin24.iteye.com/blog/2377870