2017-12-30 13 views
-2

私は良いコードで作業していますが、結果が0の場合は結果が0の場合は必要です( 'Location:checkin.php?identity ='。$ identity);mysqlからデータをフェッチしますが、結果が0の場合リダイレクト

ここに私のコード

<?php 
mysql_connect("localhost", "xxxxxx", "xxxxxx") or die("Connection Failed"); 
mysql_select_db("xxxxxx")or die("Connection Failed"); 
//added to prevent sql injection 
$identity = mysql_real_escape_string($_POST['identity']); 
$query = "select * from blacklist where identity = '$identity'"; 
$result = mysql_query($query); 
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) 
{ 
echo "{$line['number']}<br>"; 
echo "{$line['identity']}</div></td><br>"; 
echo "{$line['reason']}</div></td><br>"; 
    } 
?> 



<html> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <form method="post" name="display" action="index.php" /> 
     <b>Enter the register number:</b><br> 
     <input type="text" name="identity" /> 
     <input type="submit" value="Search" /> 
    </form> 
</html> 
+1

..だから何あなたの問題であり、選択した場合は? – Ravi

答えて

0

あなたは最初の行でこれを追加する必要があります。
そして、MySQLiを使用してください。クエリのチェックの前に

if (isset($_POST['identity'])) { 

//here your mysqli connect 
//and more 

} 

<form ....... input 
0

行の数は0です。

if(!(mysql_num_rows($result) == 0)) { 
    //Your while logic here 
} 
else 
{ 
header('Location: checkin.php?identity='.$identity); 
} 
関連する問題