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

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by diafol
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.