2016-10-25 3 views
0

実行中のスクリプトがあり、レコードを削除するページが表示されます。レコード数がゼロの場合、ページをindex.phpページにリダイレクトします。レコード数がゼロの場合のリダイレクトページ

$sql="SELECT * FROM fbi_with_invoice"; 
if ($result=mysqli_query($conn,$sql)) 
{ 
    $rowcount=mysqli_num_rows($result); 
    printf("There are %d rows remaining.\n",$rowcount); 
} 
if ($rowcount=0) { 
    header('refresh:5;url=index.php'); 
    mysqli_free_result($result); 
} 

$sql = "DELETE FROM fbi_with_invoice ORDER BY personid DESC LIMIT 1"; 

if ($conn->query($sql) === TRUE) { 
    header('refresh:5;url=index2.php'); 
} 
$conn->close(); 

現在、$rowcountは0になりますが、ページはindex2.phpにリダイレクトされます。

答えて

1

問題はここにあります:if ($rowcount = 0)==比較演算子の代わりに代入演算子を使用しました。

 $sql="SELECT * FROM fbi_with_invoice"; 
    if ($result=mysqli_query($conn,$sql)) 
    { 
    $rowcount=mysqli_num_rows($result); 
    printf("There are %d rows remaining.\n",$rowcount); 
    } 
    if ($rowcount == 0) { 
    header('refresh:5;url=index.php'); 
    mysqli_free_result($result); 
    } 
    $sql = "DELETE FROM fbi_with_invoice"; 

    if ($conn->query($sql) === TRUE && $rowcount) { 
    header('refresh:5;url=index2.php'); 
    } 
    $conn->close(); 
+0

私はそれを試みましたが、それでもindex2.phpに戻ってindex.phpに戻りません。 –

+0

また、DELETEクエリが間違っています。 '$($ conn-> query($ sql)=== TRUE && $ rowcount) 'と入力して、最後のif文に$ rowcountの検証を追加してください: ' $ sql = "fbi_with_invoiceから削除" { header( 'refresh:5; url = index2.php'); } ' – Mistery

+0

私は、SELECTとDELETEのSQLクエリの一部を混乱させていると思います。選択クエリは次のようになります。 $ sql = "SELECT * FROM fbi_with_invoice ORDER BY personid DESC LIMIT 1"; – Mistery

関連する問題