Invalid Parameter number - PHP

Asked

Viewed 181 times

0

I’m using the same code I use to make the UPDATE from another table in my bank, but when I use the code for my bank’s post table error, the only thing that’s changing is the image.

I have no idea why it’s not working because it’s the same code

Fatal error: Uncaught PDOException: 
  SQLSTATE[HY093]: Invalid parameter number: number of bound variables 
  does not match number of tokens in C:\RR\admin\edit_post.php:75 
    Stack trace: 
      #0 C:\RR\admin\edit_post.php(75): PDOStatement->execute() 
      #1 {main} thrown in C:\RR\admin\edit_post.php on line 75

the code is

<?php

error_reporting( ~E_NOTICE );
error_reporting(E_ERROR | E_PARSE);
require_once 'dbconfig.php';

if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
{
    $id = $_GET['edit_id'];
    $stmt_edit = $DB_con->prepare('SELECT titulo,descricao,texto,img FROM posts WHERE id =:uid');
    $stmt_edit->execute(array(':uid'=>$id));
    $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
    extract($edit_row);
}
else
{
    header("Location: painel_posts.php");
}



if(isset($_POST['btn_save_updates']))
{
    $titulo = $_POST['titulo'];
    $descricao = $_POST['descricao'];
    $texto = $_POST['texto'];

    $imgFile = $_FILES['user_image']['name'];
    $tmp_dir = $_FILES['user_image']['tmp_name'];
    $imgSize = $_FILES['user_image']['size'];

    if($imgFile)
    {
        $upload_dir = 'posts_images/'; // upload directory  
        $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
        $userpic = rand(1000,1000000).".".$imgExt;
        if(in_array($imgExt, $valid_extensions))
        {           
            if($imgSize < 5000000)
            {
                unlink($upload_dir.$edit_row['img']);
                move_uploaded_file($tmp_dir,$upload_dir.$userpic);
            }
            else
            {
                $errMSG = "Imagem grande demais, max 5MB";
            }
        }
        else
        {
            $errMSG = "Imagens apenas nos formatos JPG, JPEG, PNG & GIF files are allowed.";        
        }   
    }
    else
    {
        // if no image selected the old image remain as it is.
        $userpic = $edit_row['img']; // old image from database
    }               

    // if no error occured, continue ....
    if(!isset($errMSG))
    {
        $stmt = $DB_con->prepare('UPDATE posts
                                     SET titulo=:utitulo,
                                         descricao=:udescricao,
                                         texto=:utexto,
                                         img=:upic
                                   WHERE id=:uid');
        $stmt->bindParam(':utitulo',$titulo);
        $stmt->bindParam(':udescricao',$descricao);
        $stmt->bindParam(':utexto',$texto);
        $stmt->bindParam(':upic',$userpic);

        if($stmt->execute()){
            ?>
            <script>
            alert('Post Atualizado ...');
            window.location.href='painel_posts.php';
            </script>
            <?php
        }
        else{
            $errMSG = "Sorry Data Could Not Updated !";
        }

    }


}

1 answer

2


In his update is missing set id, need to insert this row before running:

$stmt->bindParam(':uid',$id);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.