簡體   English   中英

else語句不顯示數據

[英]else statement not displaying data

我有一些代碼在提交數據之前檢查db中是否有重復項,但是我的語句不起作用。 如果找到重復項,則會將消息返回到表單。 但是,它不起作用,我確定這與文件底部附近的else語句不正確有關。 假設所有連接都正常。 錯誤在哪里? 非常感謝

<?php
$array = split('[,]', $_POST['fileno']);

if (isset($_POST['submit'])) {
    foreach ($array as $fileno) {
        if ($fileno == '' && $box == '')
            {
                echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must incude a box and a file' . '</div>';

            }
        elseif ($fileno == '')
            {

                echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must enter a file reference' . '</div>';
            }
        elseif ($box == '')
            {
                //echo error;
                echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must enter a box' . '</div>';
            }
        else
            {
                $sql = "SELECT custref FROM files WHERE custref = '$fileno' ";
                $result = runSQL($sql) or die(mysql_error());
                if (mysql_num_rows($result)>0){
                    echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . $fileno . '  is already in the database. No duplicates' . '</div>';

                }
                $sql = "SELECT custref FROM boxes WHERE custref = '$box' ";
                $result = runSQL($sql) or die(mysql_error());
                if (mysql_num_rows($result)>0){
                    echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . $box . '  is already in the database. No duplicates' . '</div>';
                }

                else
                    {
                        //insert into db;
                        echo '<div style="background-color:#ffa; padding:2px; color:#33CC33;font-size:12px;font-weight:normal">' . $fileno . "Box: " . $box . $authorised . 'Successfull' . '</div>';
                        $sql = "INSERT INTO `files` (customer, authorisation, boxstatus, boxref, custref, filestatus) VALUES ('$customer', '$authorised', '$boxstatus', '$box', '$fileno', $filestatus)";
                        $result = runSQL($sql) or die(mysql_error());
                        //echo 'This record is valid';
                        //header("Location: http://localhost/sample/admin/files/index.php");
                        //exit();
                    }
            }
    }
}
?>

請檢查是否在本節中:

// Some logic
if (...) {
    // some more logic
}
...
elseif ($box == '') {
    //echo error;
    echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must enter a box' . '</div>';
}
else {
    echo 'check it here please';
    // some more logic
}
...

希望能幫助到你。

進行一些回顯以檢查值:

foreach ($array as $fileno) {
    echo "fileno='$fileno' , box='$box'<br>";
  ......

然后在if / elseif的每個塊中

echo "i'm running line : ",__LINE__,"<br>";

你得到什么?

您應該嘗試使用exit(); / die(); 在您回顯的錯誤中(不是錯誤處理的最佳方法!- 嘗試排除異常 ),而不是將相關代碼封裝在else中。 我懷疑這可能會解決您的問題,因為您只是檢查是否要針對其中一個錯誤語句添加該行。

暫無
暫無

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

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