Hello. I’m trying to update a database but I get an error: Fatal error : Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\egypt\admin\edit.php:17 Stack trace: #0 C:\xampp\htdocs\egypt\admin\edit.php(17): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\egypt\admin\edit.php on line 17 when I select the button to update the records.
I’ve checked the example I’m following, and though I have more fields, the example has the same bound variables and tokens. I assumed I would too.
Don’t know how to solve this so any help will be appreciated.
Here is the PHP:
> <?php
> require_once("dbcon/dbc.php");
>
> if(!empty($_POST["save_record"])) {
>
> $id = isset($_POST['id']) ? $_POST['id'] : NULL;
> $pagelinks = isset($_POST['pagelinks']) ? $_POST['pagelinks'] : '';
> $title = isset($_POST['title']) ? $_POST['title'] : '';
> $asideleft = isset($_POST['asideleft']) ? $_POST['asideleft'] : '';
> $body = isset($_POST['body']) ? $_POST['body'] : '';
> $asideright = isset($_POST['asideright']) ? $_POST['asideright'] : '';
> $sourceref = isset($_POST['sourceref']) ? $_POST['sourceref'] : '';
> $sourceimg = isset($_POST['sourceimg']) ? $_POST['sourceimg'] : '';
>
> $result = $dbh->prepare('UPDATE pages SET id = ?, pagelinks = ?, title = ?, asideleft = ?, body = ?, asideright, sourceref = ?, sourceimg = ? WHERE id = ?');
>
> $result->execute([$id, $pagelinks, $title, $asideleft, $body, $asideright, $sourceref, $sourceimg, $_GET['id']]);
>
> if($result) {
> header('location:index.php');
> }
> }
> $pdo_statement = $dbh->prepare("SELECT * FROM pages where id=" . $_GET['id']);
> $pdo_statement->execute();
> $result = $pdo_statement->fetchAll();
> ?>