<?php
function html_escape($input) { 
    return htmlspecialchars($input, ENT_COMPAT | ENT_HTML401, 'utf-8'); 
}
require 'connection.php';

if(!empty($_POST)) {
    $ustmt=$conn->prepare('UPDATE posts SET title = :title, body=:body, WHERE id = :id');

   $lpstid = $_GET['id'];

   $ustmt->bindValue('title', $_POST['title']);
    $ustmt->bindValue('body',$_POST['body']);
    $update_stmt->bindValue('id' , $lpstid);

    $ustmt->execute();
    while($row = $update_stmt->fetch()){
    print_r($row);
}

    if($ustmt)
    redirect('post_view.php?id='.html_escape($_GET['id']));
    }

$sstmt = $conn->prepare('SELECT (title,body) FROM posts WHERE id = :id LIMIT 1');

    $lpstid = $_GET['id'];

    $sstmt->bindValue('title', $_POST['title']);
    $sstmt->bindValue('body',$_POST['body']);
    $sstmt->bindValue('id' , $lpst_id);

    $sstmt->execute();
    //this error after execute->Invalid parameter number: number of bound variables does not match number of tokens

while($row = $sstmt->fetch()){
    print_r($row);
}
if(!$row) {
    echo 'Post #'.html_escape($_GET['id']).' not found';
    exit;
}

What i'm i missing?

Member Avatar for diafol

You only have one bound item in the SQL- :id

The SQL doesn't really make sense...

SELECT (title,body) FROM posts WHERE id = :id LIMIT 1

if you want to bind title and body.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.