php調(diào)試sql語(yǔ)句錯(cuò)誤的方法:1、通過(guò)die語(yǔ)句調(diào)試PHP SQL錯(cuò)誤;2、通過(guò)“mysql_error”語(yǔ)句調(diào)試PHP SQL錯(cuò)誤。
本文操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
php怎么調(diào)試sql語(yǔ)句錯(cuò)誤?
通過(guò)die和mysql_error語(yǔ)句調(diào)試PHP SQL錯(cuò)誤
一、代碼
<!--處理文件代碼--> <?php $conn=mysql_connect('localhost','root','root') or die("與服務(wù)器連接失敗!"); mysql_select_db('db_database22',$conn) or die("沒(méi)有找到數(shù)據(jù)庫(kù)!"); if($_POST[Submit]=="提交"){ $admin=$_POST[admin];//獲取提交的用戶名 $pass=$_POST[pass];//獲取提交的密碼 $dates=date("Y-m-d H:i:s");//定義當(dāng)前時(shí)間 $query="insert into user (admin,password,dates) values('$admin','$pass','$dates')";//編寫(xiě)添加語(yǔ)句 $result=mysql_query($query,$conn) or die(mysql_error()); //執(zhí)行添加語(yǔ)句,并返回錯(cuò)誤信息 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語(yǔ)句錯(cuò)誤</title> </head> <style type="text/css"> <!-- .STYLE1 {color: #FF0000} --> </style> <body> <!--表單提交頁(yè),設(shè)置的表單元素--> <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>
二、運(yùn)行結(jié)果
Unknown column 'password' in 'field list'
推薦學(xué)習(xí):《PHP視頻教程》