简体   繁体   中英

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. 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. My immediate thought was my HTML input fields but I've been over these like 50,000 times. Any thoughts?

PHP code:

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>

Have you tried changing this line's third parameter:

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

for

PDO::PARAM_STR

PHP Documentation says:

PDO::PARAM_STMT (integer) Represents a recordset type. Not currently supported by any drivers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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