简体   繁体   English

MySQL表名称更改后INSERT和UPDATE不起作用,但是SELECT和DELETE正常工作

[英]INSERT and UPDATE not working after MySQL table name change but SELECT and DELETE work fine

After changing a table name using phpMyAdmin and then updating my code, INSERT and UPDATE queries do not work. 使用phpMyAdmin更改表名然后更新我的代码后,INSERT和UPDATE查询不起作用。 I can perform the query in phpMyAdmin and as the title explains, DELETE and SELECT statements still work.. I'm certain my PDO prepared statement syntax is fine and the try block doesn't throw any errors. 我可以在phpMyAdmin中执行查询,正如标题所述,DELETE和SELECT语句仍然有效。.我确定我的PDO准备语句的语法很好,并且try块不会引发任何错误。 My immediate thought was my HTML input fields but I've been over these like 50,000 times. 我立即想到的是我的HTML输入字段,但是我已经遍历了50,000次。 Any thoughts? 有什么想法吗?

PHP code: PHP代码:

try {
        $stmt = $db->prepare('UPDATE signs SET sign = :sign, phonetic = :phonetic, definition = :definition, flag = :flag, modified = :modified WHERE sign_id = :sign_id');
        $stmt->bindValue(':sign_id', (int) $_POST['sign_id'], PDO::PARAM_INT);
        $stmt->bindValue(':sign', $_POST['sign'], PDO::PARAM_STR);
        $stmt->bindValue(':phonetic', $_POST['phonetic'], PDO::PARAM_STMT);
        $stmt->bindValue(':definition', $_POST['definition'], PDO::PARAM_STR);
        $stmt->bindValue(':flag', $_POST['flag'], PDO::PARAM_INT);
        $stmt->bindValue(':modified', date('Y-m-d H:i:s'), PDO::PARAM_STR);
        $stmt->execute();
        $_SESSION['success'] = 'Definition updated successfully.';
        header('Location: 'dictionary.php');
        exit;
    } catch (PDOException $e) {
        $_SESSION['error'] = 'An error occurred while connecting to the database.'.$e->getMessage();
        error_log($e->getMessage(), 0);
    }

HTML code: HTML代码:

<form method="post" role="form">
                    <fieldset>
                        <input type="hidden" name="sign_id" value="<?= $row->sign_id; ?>">
                        <div class="form-group">
                            <label>Sign
                                <input name="sign" type="text" value="<?= $row->sign; ?>" class="form-control" placeholder="Sign">
                            </label>
                        </div>
                        <div class="form-group">
                            <label>Phonetic
                                <input name="phonetic" type="text" value="<?= $row->phonetic; ?>" class="form-control" placeholder="Phonetic">
                            </label>
                        </div>
                        <div class="form-group">
                            <label>Definition
                                <textarea name="definition" class="form-control" placeholder="Definition"><?= $row->definition; ?></textarea>
                            </label>
                        </div>
                        <div class="form-group">
                            <label>Flag
                                <select name="flag" class="form-control">
                                    <option value="0" <? if ($row->flag == 0) echo "selected"; ?>>None</option>
                                </select>
                            </label>
                        </div>
                        <div class="form-group">
                            <input name="submit" type="submit" value="Save" class="btn btn-primary">
                        </div>
                    </fieldset>
            </form>

Have you tried changing this line's third parameter: 您是否尝试过更改此行的第三个参数:

$stmt->bindValue(':phonetic', $_POST['phonetic'], PDO::PARAM_STMT);

for 对于

PDO::PARAM_STR

PHP Documentation says: PHP文档说:

PDO::PARAM_STMT (integer) Represents a recordset type. PDO :: PARAM_STMT(整数)表示记录集类型。 Not currently supported by any drivers. 当前不受任何驱动程序支持。

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

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