Versio

[PDO] Onverklaarbare error

Overzicht Reageren

Jonathan -

Jonathan -

07/07/2010 23:44:26
Quote Anchor link
Hallo jongens,

PDO geeft om de één of andere reden een warning, maar nadat ik zelf vijf keer de code van boven tot beneden gelezen heb, ben ik er nog niet achter wat de gemaakte fout nou is. Daarom post ik het maar even hier.

Het regelnummer waarop de warning gegeven werd komt in deze snippet overeen met regel 59.

Quote:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

$query
=
"INSERT INTO
    book
    (
        title,
        subtitle,
        author_others,
        price,
        price_old,
        isbn10,
        isbn13,
        publisher_id,
        edition_id,
        pages,
        category_id,
        show,
        description_short,
        description,
        created_at
    )
VALUES
    (
        :title,
        :subtitle,
        :author_others,
        :price,
        :price_old,
        :isbn10,
        :isbn13,
        :publisher_id,
        :edition_id,
        :pages,
        :category_id,
        :show,
        :description_short,
        :description,
        NOW()
    );"
;

$stmt = $pdo->prepare($query);

$stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$stmt->bindParam(':subtitle', $_POST['subtitle'], PDO::PARAM_STR);
$stmt->bindParam(':author_others', $_POST['author_others'], PDO::PARAM_BOOL);
$stmt->bindParam(':price', $_POST['price'], PDO::PARAM_STR);
$stmt->bindParam(':price_old', $_POST['price_old'], PDO::PARAM_STR);
$stmt->bindParam(':isbn10', $_POST['isbn10'], PDO::PARAM_STR);
$stmt->bindParam(':isbn13', $_POST['isbn13'], PDO::PARAM_STR);
$stmt->bindParam(':publisher_id', $_POST['publisher'], PDO::PARAM_INT);
$stmt->bindParam(':edition_id', $_POST['edition'], PDO::PARAM_INT);
$stmt->bindParam(':pages', $_POST['pages'], PDO::PARAM_INT);
$stmt->bindParam(':category', $_POST['category'], PDO::PARAM_INT);
$stmt->bindParam(':show', $_POST['show'], PDO::PARAM_BOOL);
$stmt->bindParam(':description_short', $_POST['description_short'], PDO::PARAM_STR);
$stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);

$stmt->execute();

?>


Hopelijk ziet iemand het probleem!

Groet, Jonathan

Edit: de oplossing is net aangedragen via Twit-ter.
Gewijzigd op 07/07/2010 23:52:13 door Jonathan -
 
PHP hulp

PHP hulp

25/05/2012 09:53:34
Gesponsorde koppelingen:
BHosted Hosting al vanaf € 1,- per maand

Controleer nu gratis jouw domeinnaam:

  
 
Piet Verhagen

Piet Verhagen

07/07/2010 23:52:55
Quote Anchor link
Je weet zeker dat al die $_POST['...'] vars bestaan? Controleer je in de code daarop?
 
Jelmer rrrr

Jelmer rrrr

07/07/2010 23:55:59
Quote Anchor link
In de extreem onwaarschijnlijke situatie waarbij iemand echt nodig de oplossing wil weten, maar twitter onbereikbaar is (okee, dat is niet zoo onwaarschijnlijk)

De oplossing was: in de query staat :category_id maar hij roept bindParam aan met :category, zonder _id.
 
- SanThe -

- SanThe -

07/07/2010 23:59:58
Quote Anchor link
Jelmer rrrr op 07/07/2010 23:55:59:
In de extreem onwaarschijnlijke situatie waarbij iemand echt nodig de oplossing wil weten, maar twitter onbereikbaar is (okee, dat is niet zoo onwaarschijnlijk)


Niet zo onwaarschijnlijk hoor.
Thanks.
 



Overzicht Reageren