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

时间:2015-09-29 06:59:04

标签: php html mysql pdo

使用phpMyAdmin更改表名然后更新我的代码后,INSERT和UPDATE查询不起作用。我可以在phpMyAdmin中执行查询,正如标题所解释的那样,DELETE和SELECT语句仍然有效。我确定我的PDO预处理语句语法很好,并且try块不会抛出任何错误。我的直接想法是我的HTML输入字段,但我已经超过了50,000次。有什么想法吗?

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:

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

1 个答案:

答案 0 :(得分:0)

您是否尝试更改此行的第三个参数:

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

PDO::PARAM_STR

PHP文档说:

  

PDO :: PARAM_STMT(整数)       表示记录集类型。目前不支持任何驱动程序。

相关问题