在收件箱中插入數據時,與mysql數據比較時會顯示錯誤信息。 我dbcon.php文件php索引值與sql數據庫值匹配不起作用
<?php
define('DB_server','localhost');
define('DB_user','root');
define('DB_pass','');
define('DB_Name','dbtuts');
class DB_con
{
\t function __construct()
\t {
\t $con=mysql_connect(DB_server,DB_user,DB_pass) or die('connection problem'.mysql_error());
\t mysql_select_db(DB_Name,$con);
\t
\t }
\t
\t public function comp($lnum)
\t {
\t $res = "SELECT * FROM users WHERE l_num= '".$_GET["$lnum"]."'";
\t return $res;
\t }
\t
\t
}
?>
這裏數據庫表中的值f_num,l_num,和與我compare.php文件
<?php
include_once 'dbcon.php';
$con=new DB_con();
if(isset($_POST['log']))
\t {
\t
\t $lnum=$_POST['li_num'];
\t $res=$con->comp($lnum);
\t if($res){
\t while($row = mysql_fetch_array($res)) {
\t $num=$row['li_num'];
\t
\t ?>
\t <script>
\t
\t alert("thnks for login")
\t </script>
\t <?php
\t }
\t }
}
\t ?>
<html>
\t <head>
\t <title>Enter customer value</title>
\t </head>
\t <body>
\t <center>
\t \t <form method="POST">
\t \t \t <table align="center">
\t \t \t <tr>
\t \t \t <td><input type="text" name="fi_num" placeholder="enter value" required> name</td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t <td><input type="text" name="li_num" placeholder="enter extra"> password</td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t <td><input type="text" name="sum" placeholder="enter sum"> sum</td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t <td><button type="submit" name="log">login</button></td>
\t \t \t </tr>
\t \t \t </table>
\t \t </form>
\t </center>
\t </body>
</html>
時我點擊登錄按鈕兩個錯誤來到
Notice: Undefined index in dbcon.php and
Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in compare.php
任何建議,這problem.it將有助於我
您需要使用mysqli_ * –
$ lnum的值是多少? –
你正在'發佈'表單,但'GET'變量。這是行不通的。並切換到mysqli或PDO。 mysql_ *函數已被棄用,並從PHP7開始被刪除。這兩個庫將允許您防止SQL注入。 – aynber