help with a crud

1

my error is this: PDOException: SQLSTATE [HY093]: Invalid parameter number: parameter was not defined in C: \ wamp \ www \ form persona1 \ form person1 \ Model \ modelperson.php on line 55

this is my view

this is the model

function editarpersona()
{
    $sql = "UPDATE persona SET nombre=?, apellido=?, fecha_ingre=?,
    edad=?";
    $obj = $this->conex->prepare($sql);
    $obj->bindValue(2,$_POST['nombre'], PDO::PARAM_STR);
    $obj->bindValue(3,$_POST['apellido'], PDO::PARAM_STR);
    $obj->bindValue(4,$_POST['fecha_ingre'],PDO::PARAM_STR);
    $obj->bindValue(5,$_POST['edad'], PDO::PARAM_STR);
    $obj->execute();
}

my driver      require_once ("../ Modelo / modelopersona.php");

$obj = new persona();
if (isset($_POST['cedula']))
{
    $value = $obj->mostrarpersona();
}

if (isset($_POST['enviar']) and $_POST['enviar']=='si')
{
    $value = $obj->editarpersona();
    var_dump($obj);
}
require_once("../Vista/vistaeditar.php");

? >

    
asked by Anibal Peña 22.04.2017 в 04:14
source

1 answer

2

The error has to do with the amount of parameters you are using when doing bindValue() .

Your sql has 4 parameters identified with "?", which should be numbered from 1 to 4, but in bindValues you use identifiers 2 through 5, so you leave a "?" without replacing, and therefore the error of the missing parameter.

Fixed, your code would be:

function editarpersona() {
    $sql = "UPDATE persona SET nombre = ?, apellido = ?, fecha_ingre = ?, edad = ?";
    $obj = $this->conex->prepare($sql);
    $obj->bindValue(1, $_POST['nombre'], PDO::PARAM_STR);
    $obj->bindValue(2, $_POST['apellido'], PDO::PARAM_STR);
    $obj->bindValue(3, $_POST['fecha_ingre'], PDO::PARAM_STR);
    $obj->bindValue(4, $_POST['edad'], PDO::PARAM_STR);
    $obj->execute(); 
}

A similar case is documented as example # 2 of the PHP manual PDOStatement :: bindvalue

    
answered by 22.04.2017 в 07:01