-1

[STDERR] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/vhosts/keciorenakkusnakliyat.com/httpdocs/inc/head.php:19

I can't find what's wrong in my code. Code snippet head.php:

<?php
include 'trex/controller/config.php'; 
include 'trex/controller/seo.php';
date_default_timezone_set('Europe/Istanbul');
$settings=$db->prepare("SELECT * from ayar where ayar_id=?");
$settings->execute(array(0));
$settingsprint=$settings->fetch(PDO::FETCH_ASSOC);

$social=$db->prepare("SELECT * from sosyal");
$social->execute();

$socialf=$db->prepare("SELECT * from sosyal");
$socialf->execute();

$socials=$db->prepare("SELECT * from sosyal");
$socials->execute();

$motor=$db->prepare("SELECT * from motor where motor_id=1");
$motor->execute(array(0));
$motorprint=$motor->fetch(PDO::FETCH_ASSOC);

$widgets=$db->prepare("SELECT * from widget where widget_id=1");
$widgets->execute(array(0));
$widgetprint=$widgets->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="trex/<?php echo $settingsprint['ayar_fav']; ?>"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="css/icomoon.css">
    <link rel="stylesheet" href="css/rev-settings.css">
    <link rel="stylesheet" type="text/css" href="css/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="css/slider.css">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" type="text/css" href="css/switcher.css">
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" type="text/css" href="css/default.css">
    <link rel="stylesheet" type="text/css" href="css/styles.css" id="colors">
    <link href="https://fonts.googleapis.com/css?family=Fira+Sans:100,200,300,400,500,600,700,800,900" rel="stylesheet">
    <link rel="stylesheet" href="css/lightbox.css">
    <link href="trex/assets/lib/sweet-alerts2/sweetalert2.min.css" rel="stylesheet">
    <?php 
    echo $motorprint['motor_yonay']; 
    echo $motorprint['motor_gonay']; 
    ?>

Error :

enter image description here

In DB

enter image description here

i don't know what is the problem ??

ADyson
  • 57,178
  • 14
  • 51
  • 63
Levvo06
  • 1
  • 2
  • What is this array(0)? – Your Common Sense Aug 16 '23 at 20:11
  • In this case, the placeholder doesn't seem to match any in the query itself (no placeholders in the query), so the value 0 doesn't actually correspond to anything in the query. but still not working – Levvo06 Aug 16 '23 at 20:22
  • yes. That's the point exactly. Which perfectly matches the error message you get. – Your Common Sense Aug 16 '23 at 20:23
  • Can you describe it to me to solve it? – Levvo06 Aug 16 '23 at 20:25
  • Didn't you already explained it yourself? If no placeholders in the query, then you shouldn't provide any values? – Your Common Sense Aug 16 '23 at 20:31
  • $motor = $db->prepare("SELECT * FROM motor WHERE motor_id = ?"); $motor->execute(array(1)); $motorprint = $motor->fetch(PDO::FETCH_ASSOC); its work – Levvo06 Aug 16 '23 at 20:32
  • @Levvo06 Or you could just write `$motor = $db->prepare("SELECT * FROM motor WHERE motor_id = 1"); $motor->execute(); $motorprint = $motor->fetch(PDO::FETCH_ASSOC);` without any parameters. A parameter which is actually just used to send a fixed value doesn't really give you any advantage. Parameters are useful when you need to include some uncertain value into the query, such as data from user input, or the result of a calculation. – ADyson Aug 16 '23 at 22:48

0 Answers0