mySQL bindValue issue....

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jul 05, 2012 7:43 pm

mySQL bindValue issue....

Postby ellypho » Thu Jul 05, 2012 7:51 pm

Hello phpF,

I've been learning php/mySQL thru a manual by sitepoint and have run into a problem trying to complete a challenge in the book.

They've asked me to create a delete confirmation screen for a db of jokes. I'd like to list the the name of the author to be deleted and all of his/her jokes. I believe the bindValue command is causing me issues...
Any insight as to what my be wrong in this code would be great help. Cheers!

Code: Select all

        include $_SERVER['DOCUMENT_ROOT'] . '/phpbed/includes/dbconnect.php';
        echo 'test3<br>';
        echo 'id ' . $_POST['id'] . '<br>';
        echo $_POST['id'];
        $sql = 'SELECT joketext FROM joke WHERE authorid = :id';
        $sql->bindValue(':id', $_POST['id']);
        $result = $pdo->query($sql);
        echo "test4";
        while ($row = $result->fetch())
            $joke[] = $row['joketext'];
        echo 'test5';
        including all of this authors jokes?
            <?php foreach ($joke as $bleh): ?>
            <p><?php echo $bleh; ?> </p>
        <?php endforeach; ?>

Please note that i've plopped a bunch of test echoes and i can't seem to get past test4.

Thanks guys!

php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: mySQL bindValue issue....

Postby johnj » Fri Jul 06, 2012 7:51 am

do a var_dump($result), var_dump($row) and see if there is an error.

Are you sure that $_POST['id'] has a value?

Also, Take a look at this example:

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest