简体   繁体   English

mysqli update即使声明成功也没有更新?

[英]mysqli update not updating eventhough stating successful?

I am building a project and for some reason, I am unable to get my Update statement to actually update. 我正在构建一个项目,由于某种原因,我无法获取我的Update语句进行实际更新。

I have some input fields in a form which provide the details for the variables below. 我在表格中有一些输入字段,其中提供了以下变量的详细信息。

Here's my code: 这是我的代码:

//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.";
        }

I have tested and the variables are being set from my form ok, and when I run the script , I get the 'success' message but check my database and nothings happened. 我已经测试过,并且可以从我的表单中确定变量,然后运行脚本时,我收到“成功”消息,但检查我的数据库,什么都没发生。

Anything I've missed? 我有什么想念的吗? :) :)

Thanks for your help/ 谢谢你的帮助/

OK< existing form/ table below: 确定<现有的下表/表格:

<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>

I have tried the SQL commend in my database direct, and it works. 我已经尝试直接在数据库中使用SQL命令,并且可以使用。 Just doesnt work via this form. 只是不能通过这种形式工作。 DB is connected and form is able to pull data from the database. DB已连接,并且表单能够从数据库中提取数据。

UPDATE: I've tried everything I an think of - nothing is working here. 更新:我已经尝试了所有我想到的东西-这里没有任何工作。 I've added error reporting to each step, and because it thinks nothing is wrong, no errors are flagging up! 我在每个步骤中都添加了错误报告,因为它认为没有错,所以没有错误提示! I have update access to the SQL as I use it all the time. 我一直使用SQL,因此我具有对SQL的更新访问权限。

This is likely to be due to one of two problems. 这可能是由于两个问题之一。

-Either your $id is not matching an entry in your DB table or: -您的$ id与数据库表中的条目不匹配,或者:

-Your mysql user does not have update priveleges. -您的mysql用户没有更新权限。

Given what you said about the query working on the back end, the second option seems most likely. 鉴于您所说的有关在后端运行查询的内容,第二种选择似乎很有可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM