0

我正在构建一个项目,由于某种原因,我无法让我的 Update 语句实际更新。

我在表单中有一些输入字段,它们提供了以下变量的详细信息。

这是我的代码:

//update database

$stmt = $mysqli->prepare("UPDATE pages SET 
                    pg_name= ?, 
            pg_title = ?, 
            pg_keywords = ?,
            pg_description = ?,
            pg_header1 = ?,
            pg_header2 = ?,
            pg_maintext = ?,
            pg_active = ? WHERE id = ?");

        $stmt->bind_param('sssssssii', 
            $pg_name,
            $pg_title,
            $pg_keywords,
            $pg_description,
            $pg_header1,
            $pg_header2,
            $pg_maintext,
            $pg_active,
            $id);
        if($stmt->execute() === TRUE){
        $stmt->close();
            echo "Database successfully updated";
        } else {
            echo "There was a problem updating the database.";
        }

我已经测试过并且变量正在从我的表单中设置好,当我运行脚本时,我收到“成功”消息,但检查我的数据库并没有发生任何事情。

我错过了什么?:)

谢谢你的帮助/

好的<现有表格/下表:

<form action="" method="post">
    <table>
        <tr>
            <td colspan="2"><?php echo "<span style='color: red; font-weight:     bold;'>".$errmsg."</span><br />"; ?></td>
        </tr>
        <tr>
            <td>Page Name:</td>
            <td><input type="text" name="pg_name" id="pg_name" value="<?php     if(isset($id)){ echo $page['pg_title']; }?>" /></td>
        </tr>
        <tr>
            <td>Page Title:</td>
            <td><input type="text" name="pg_title" id="pg_title" value="<?php     if(isset($id)){ echo $page['pg_title']; }?>" /></td>
        </tr>
        <tr>
            <td>Keywords:</td>
            <td><input type="text" name="pg_keywords" id="pg_keywords" value="    <?php if(isset($id)){ echo $page['pg_keywords']; }?>" /></td>
        </tr>
        <tr>
            <td>Description:</td>
            <td><input type="text" name="pg_description" id="pg_description"      value="<?php if(isset($id)){ echo $page['pg_description']; }?>"/></td>
        </tr>
        <tr>
            <td>Main page header:</td>
            <td><input type="text" name="pg_header1" id="pg_header1"  value="<?    php if(isset($id)){ echo $page['pg_header1']; }?>"/></td>
        </tr>
        <tr>
            <td>Subheader:</td>
            <td><input type="text" name="pg_header2" id="pg_header2" value="<?    php if(isset($id)){ echo $page['pg_header2']; }?>" /></td>
        </tr>
        <tr>
            <td>Page text</td>
            <td><textarea name="pg_maintext" id="pg_maintext"><?php     if(isset($id)){ echo $page['pg_maintext']; }?></textarea></td>
        </tr>
        <tr>
            <td>Active?</td>
            <td><select name="pg_active">
                <option value="1">Yes</option>
                <option value="0">No</option>
                </select></td>
        </tr>
        <tr>
            <td><input type="submit" name="submit" id="submit" value="<?php     if(isset($_GET['page_id'])){ echo "Update"; } else { echo "Add"; } ?>" /><?php     if(isset($_GET['page_id'])){ echo "<a href='pages.php' /><input type='button' name='new'     id='new' value='New' /></a>"; } ?></td>
            <td></td>
        </tr>
    </table>
</form>

我已经直接在我的数据库中尝试了 SQL 推荐,它可以工作。只是不能通过这种形式工作。数据库已连接,表单能够从数据库中提取数据。

更新:我已经尝试了所有我想到的东西——这里没有任何效果。我在每个步骤中都添加了错误报告,因为它认为没有任何问题,所以没有错误出现!因为我一直在使用它,所以我拥有对 SQL 的更新访问权限。

4

1 回答 1

0

This is likely to be due to one of two problems.

-Either your $id is not matching an entry in your DB table or:

-Your mysql user does not have update priveleges.

Given what you said about the query working on the back end, the second option seems most likely.

于 2013-09-27T09:17:47.947 回答