簡體   English   中英

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

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

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

您是否嘗試過更改此行的第三個參數:

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

對於

PDO::PARAM_STR

PHP文檔說:

PDO :: PARAM_STMT(整數)表示記錄集類型。 當前不受任何驅動程序支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM