SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP on bindValue() !! I got a fatal error, please teach me how to fix it.

    I got this Fatal error: Call to a member function bindValue() on a non-object in c:\wamp\www\addjoke\index.php on line 51.
    What does it mean and how to fix it? Below is the code teached by book, after i execute it, the browser gave me fatal error on bindValue.
    Any opinion will be appreciate.

    if(isset($_POST['joketext']))
    {
    try
    {
    $sql='INSERT INTO joke SET
    joketext = :joketext,
    jokedate = CURDATE()';
    $S=$pdo->prepare($sql);
    $s->bindValue(':joketext',$_POST['joketext']);
    $s->execute();
    }
    catch(PDOException $e)
    {
    $error='Error adding submitted joke: ' . $e->getMessage();
    include 'error.html.php';
    exit();
    }
    header ('Location: .');
    exit();
    }

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Think you'll find your answer a bit more subtle..
    Code:
    $S=$pdo->prepare($sql);
    $s->bindValue(':joketext',$_POST['joketext']);
    s != S

    Your error message tells you that $s doesnt have a 'bindValue' method. And it doesnt, because $s is undefined. $S is defined, as an object type PDOStatement. $S has a method bindValue....
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks your help, really appreciate it. I think i overlooked it for 2 days, keep finding the mistake...haha! Thank you very much! Now, it's working!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •