温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php如何调试sql语句错误

发布时间:2021-07-13 18:02:35 来源:亿速云 阅读:150 作者:chen 栏目:编程语言

本篇内容主要讲解“php如何调试sql语句错误”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php如何调试sql语句错误”吧!

php调试sql语句错误的方法:1、通过die语句调试PHP SQL错误;2、通过“mysql_error”语句调试PHP SQL错误。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

php怎么调试sql语句错误?

通过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'

到此,相信大家对“php如何调试sql语句错误”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI