php - 更新php表中的数据时黑屏

标签 php mysql html mysqli

我一直在从事一个项目,目前正处于该项目的最后阶段。我的问题是,每当我尝试将数据库表中的数据更新为返回空白屏幕时,没有错误消息。请在下面找到php脚本和html表单(负责更新数据库表的表单),我将其分为大约四个部分:

提前致谢

更新表单:

<a name="inventoryEditForm" id="inventoryEditForm"></a>
<h3>&darr;Add New Question Form&darr;</h3>  
<form action="inventory_edit.php" enctype="multipart/from-data" name="myForm" id="myForm" method="post">
    <table width="80%" border="0" cellspacing="3" cellpadding="7">
        <tr>
            <td width="20%">&nbsp;</td>
            <td width="80%">&nbsp;</td>
        </tr>
        <tr>
            <td>Question</td>
            <td><textarea rows="" name="question" cols=""><?php echo $question; ?></textarea></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>Venue</td>
            <td><input type="text" name="venue" maxlength="50" value="<?php echo $venue; ?>"></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>Date</td>
            <td><input type="date" name="questiondate" value="<?php echo $date; ?>"></td>
        </tr>
    </table>
    <br>
    <input name="thisID" type="hidden" value="<?php echo $targetID; ?>"/>
    <input type="submit" name="submit" value="Update Question">
    <input type="reset" name="clear" value="Clear Form">
</form>

PHP 脚本:

<?php

//Error reporting due to long script
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php

error_reporting(E_PARSE);
//Update question table
If (isset($_POST['question'])) {
    $id = mysqli_real_escape_string($link, $_POST['thisID']);
    $question = mysqli_real_escape_string($link, $_POST['question']);
    $venue = mysqli_real_escape_string($link, $_POST['venue']);
    $date = mysqli_real_escape_string($link, $_POST['questiondate']);
    //Update question in the table
    $sql = mysqli_query($link, "UPDATE DebateQuestion SET question='$question',venue='$venue',date='$date' WHERE qQuestionNo='$id'LIMIT 1") or die(mysql_error());
    header("location: inventory.php");
    exit();
}
?>
<?php

error_reporting(E_PARSE);
//Gather this questions full information and insert automatically into the edit form
if (isset($_GET['qid'])) {
    $targetID = $_GET['qid'];
    $sql = mysqli_query($link, "SELECT * FROM DebateQuestion WHERE qQuestionNo='$targetID'LIMIT 1") or die(mysql_error());
    $questionCount = mysqli_num_rows($sql); // count the output amount

    if ($questionCount > 0) {
        while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)) {
            $id = $row["qQuestionNo"];
            $question = $row["qQuestion"];
            $venue = $row["qDebateVenue"];
            $date = strftime("%b %d, %Y", strtotime($row["qDate"]));
        }
    } else {
        echo "Oops, no questions like that exists. Check <a href='inventory.php'>inventory</a>again";
        exit();
    }
}
?>

最佳答案

在你的更新查询中,你的数据列没有使用`反引号,日期也是mysql的函数,如果你不确定它们是否与mysql的保留关键字冲突,请尝试用反引号包裹你的列名

$sql = mysqli_query($link,"UPDATE DebateQuestion SET 
`question`='$question',`venue`='$venue',`date`='$date' 
 WHERE qQuestionNo='$id'LIMIT 1")

关于php - 更新php表中的数据时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18621264/

相关文章:

html - CSS tr :hover and anchor tags

php - iSeries 上的 PDO ODBC 到 IBM DB2 导致 Ubuntu Server 上出现段错误

php - 获取选中和未选中的复选框值

php - 如何在不使用LOAD DATA INFILE的情况下向MySQL表中插入大量数据?

mysql - Visual Studio 2013 MVC MySql 连接

mysql - SQL_NO_CACHE 是否适用于整个查询,包括子查询?

php - 如何使用 .htaccess 检测浏览器

javascript - 将图像拖放到 Canvas 中

php - 可能 "undo"在 PHP 脚本中发送 HTTP header 和此类中间执行?

php - CakePHP:根据配置值全局更改所有模型的数据库连接