簡體   English   中英

mysqli查詢不返回任何結果或錯誤的PHP代碼

[英]mysqli query not returning any result or error php code

我有一個數據輸入PHP代碼。 我允許用戶選擇要在單獨頁面上顯示的表格以便於訪問。 我可以獲取代碼將選定的表插入“maintable”表,但我無法從該表中獲取任何信息。 即使在我插入該數據庫的同一頁面上,插入表文件也不會從中獲取當前表名。 所以我想如果我能解決這個問題,我也可以解決這個問題。 維護表只有一列,其中一個記錄在我的其他數據庫中。 我這樣做是為了讓用戶無法直接訪問它,因為他們可以看到不同數據庫中的所有其他表。

data-entry-header.php文件有我的連接語句,$ connect是我用於此數據庫連接的連接語句。 我得到的結果是我的main-form.php文件沒有表名。 所以它不會拋出任何錯誤,它只是沒有得到表名。 我知道我的連接語句和表/列名稱是正確的,因為我使用了相同的插入語句。

include 'data-entry-header.php';
    $keys = array();

    /* Query for Main Table Value */
    $string = 'SELECT TableName FROM maintable';
    $resultMain = mysqli_query($connect, $string) or die(mysqli_error($link));
    while ($rowMain = mysqli_fetch_row($resultMain)){
        $table = $rowMain[0];
    }

    /* Display Message or Table */
    if ($table = NULL || $table = "" ){
        echo 'No Main Table has been set. Go to the <a href="set-main-table.php">Set Main Table</a> page to select a Main Table.';
    }
    else {
        include 'main-form.php';
    }

    /* Get footer Contents */
    include "../footer.php";
if ($table = NULL || $table = "" ){

你把配置=與比較==混淆了

你應該嘗試:

if ($table == NULL || $table == "" ){

您的代碼還有許多其他錯誤。

  • 而不是die() ,你必須使用更方便的trigger_error(); 這不會向任何人透露敏感信息。
  • 如果你只期望一個結果,那么循環就沒有意義了
  • PHP是一種松散類型的語言。 不需要過多的條件。 只是if($table)足以滿足大多數情況
  • 使用有意義(和一致 )的變量名稱也有很大幫助

     $sql = 'SELECT TableName FROM maintable'; $res = mysqli_query($connect, $sql) or trigger_error(mysqli_error($connect)); // $connect, not $link ^ $row = mysqli_fetch_row($res); /* Display Message or Table */ if (!$row){ echo 'No Main Table has been set. Go to the <a href="set-main-table.php">Set Main Table</a> page to select a Main Table.'; } else { $table = $row[0]; include 'main-form.php'; } 

而不是或死,只需在下面添加

echo mysqli_error($link);

另外,在您的查詢中,它不是columnName FROM table嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM