SQL: The query works, but goes a mistake?

The query works, but I get an error trying to see the error but it can not. All variable get "value='1' " when marked....

$tuning = SESSION['tuning']));
$garanciq = (!empty($_SESSION['garanciq']));
$avtopilot = (!empty($_SESSION['avtopilot'])); 
$servo = (!empty($_SESSION['servo']));   
$tiptronik = (!empty($_SESSION['tiptronik']));
$servo = (!empty($_SESSION['servo']));
$service = (!empty($_SESSION['service']));
$bord = (!empty($_SESSION['bord']));
$navi = (!empty($_SESSION['navi']));
$volan = (!empty($_SESSION['volan']));  
$zastrahovka = (!empty($_SESSION['zastrahovka']));    

$iInsert= new general();
$iInsert->query("INSERT INTO  other_checkbox 
                 (tuning, garanciq, avtopilot, servo, tiptronik,
                  bord_komp, serviz_knijka, navig_sistema, desen_volan, 
                  zastrahovka) 
                 VALUES " . "(:tuning, :garanciq, avtopilot, :servo, 
                              :tiptronik, :bord, :serviceBook, :navi, 
                              :volan, :zastrahovka)");

$iInsert->bind(':tuning', $tuning);
$iInsert->bind(':garanciq', $garanciq);
$iInsert->bind(':avtopilot', $avtopilot);
$iInsert->bind(':servo', $servo);
$iInsert->bind(':tiptronik', $tiptronik);
$iInsert->bind(':bord', $bord);
$iInsert->bind(':serviceBook', $service);
$iInsert->bind(':navi', $navi);
$iInsert->bind(':volan', $volan);
$iInsert->bind(':zastrahovka', $zastrahovka);
$iInsert->execute();
$iInsert->debugDumpParams(); ->get error, but have Fatal Error !
$insert_other_chek = $iInsert->lastInsertId();->get LastInsertId

I get this error

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\test\ClassGeneral.php on line 45

Fatal error: Call to undefined method general::debugDumpParams() in C:\xampp\htdocs\test\publicFinish.php on line 165

This is my class General !

class general {

    private $db;
    private $stmt;

    public function __construct() {
        $this->db = new connect();
        $this->db = $this->db->connectDb();
    }
    public function query($sql) {
        $this->stmt = $this->db->prepare($sql);
    }  
    public function execute() {
        return $this->stmt->execute();
    }    
}

Upvotes: 0

Views: 67

Answers (4)

Your Common Sense
Your Common Sense

Reputation: 157880

Let me give you an advise. Do not use that class from culttt article.

It doesn't make any good compared to vanilla PDO, but has some serious drawbacks.

$stmt = $pdo->prepare("INSERT INTO  other_checkbox 
             (tuning, garanciq, avtopilot, servo, tiptronik,
              bord_komp, serviz_knijka, navig_sistema, desen_volan, 
              zastrahovka) 
             VALUES (:tuning, :garanciq, :avtopilot, :servo, 
                          :tiptronik, :bord, :serviceBook, :navi, 
                          :volan, :zastrahovka)");

$stmt->execute(array($tuning, $garanciq,$avtopilot,$servo,$tiptronik,
               $bord,$service,$navi,$volan, $zastrahovka));
$insert_other_chek = $stmt->lastInsertId();

is all the code you need.

Upvotes: 0

M0rtiis
M0rtiis

Reputation: 3784

replace

avtopilot

with

:avtopilot

in query

$iInsert->query("
    INSERT INTO  other_checkbox 
        (tuning, garanciq, avtopilot, servo, tiptronik, bord_komp, serviz_knijka, navig_sistema, desen_volan, zastrahovka) 
    VALUES
        (:tuning, :garanciq, :avtopilot, :servo, :tiptronik, :bord, :serviceBook, :navi, :volan, :zastrahovka)
");

Upvotes: 3

Pavel D
Pavel D

Reputation: 70

You don't have function bind() into the class general

Upvotes: -1

Alexis Peters
Alexis Peters

Reputation: 1631

in your class general you don't have the functions bind and debugDumpParams

Upvotes: 1

Related Questions