【问题标题】:INSERT and UPDATE not working after MySQL table name change but SELECT and DELETE work fineMySQL 表名更改后 INSERT 和 UPDATE 不起作用,但 SELECT 和 DELETE 工作正常
【发布时间】:2015-09-29 06:59:04
【问题描述】:

使用 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 代码:

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

【问题讨论】:

  • 尝试重启mysql服务器。
  • 您发布的 PHP 代码有一个错误:“位置”行有三个撇号:'
  • 我怀疑您的查询是否已运行。这就是为什么它没有抛出错误
  • @Michael 我在发布之前修改了该行。

标签: php html mysql pdo


【解决方案1】:

你有没有试过改变这行的第三个参数:

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

PDO::PARAM_STR

PHP 文档说:

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

【讨论】:

  • 噢!看起来我依赖于代码完成。
猜你喜欢
  • 2014-03-17
  • 2012-07-07
  • 1970-01-01
  • 2011-12-02
  • 2016-04-18
  • 1970-01-01
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多