PHP PDOStatement::execute(): SQLSTATE[HY093]

69 Views Asked by At

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xamppp\htdocs\porto\yonetim\network\islem.php on line 14

I GET AN ERROR

Project Source: https://www.youtube.com/watch?v=Kwy40bF_0Fg&list=PLZtkgIR0fgTHt1ZaDskLfv3WwVTdCYDIU&index=12

<?php 
    ob_start();
    include 'baglan.php';
    if (isset($_POST['genelayarkaydet'])) {
        $ayarkaydet=$db->prepare("UPDATE ayar SET
ayar_siteurl=:ayar_siteurl,
ayar_title=:title
WHERE ayar_id=0");

        $update = $ayarkaydet -> execute(array(
'siteurl' => $_POST['ayar_siteurl'],
'title' => $_POST['ayar_title']
));

        if ($update) {
            echo "Başarılı..";
        }
    }
?>
2

There are 2 best solutions below

3
Marh On

Try this:

$update = $ayarkaydet->execute([
':aray_siteurl' => $_POST['ayar_siteurl'],
':title' => $_POST['ayar_title']]);
0
Nancy Moore On

Your code has so many typo errors. Your execute statement is wrong.

Again I was wondering what ayar_id = 0 is doing. I believe this is supposed to be a unique value for database incrementations. If yes then your table creation is wrong.

For instance you can also make ayar_id an int and a primary key

Eg. create table ayar(ayar_id int primary key auto_increment, ayar_title varchar(3));

The primary key will set the value of ayar_id to 1 for the first insert counting up. Anyway since your ayar_id is 0. I have re-written the code for you

<?php 
ob_start();
include 'baglan.php';

/*  my own db connections
$db = new PDO (
    'mysql:host=localhost;dbname=your_db_name;charset=utf8', 
    'root', // username

    '' // password
);
*/

if (isset($_POST['genelayarkaydet'])) {


 $ayarkaydet=$db->prepare("UPDATE ayar SET ayar_siteurl=:ayar_siteurl,ayar_title=:ayar_title WHERE ayar_id=:ayar_id");

        $ayarkaydet->execute(array(
            'ayar_siteurl' => $_POST['ayar_siteurl'],
'ayar_title' => $_POST['ayar_title'],
'ayar_id' => '0'
    ));


if ($ayarkaydet) {
    echo "Başarılı..";
}


}


 ?>