Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mySQL bindValue issue....

Codes here !

Moderators: macek, egami, gesf

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
<?php
       
        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';
        ?>
        <div>
        including all of this authors jokes?
        </div>
            <?php foreach ($joke as $bleh): ?>
       
        <blockquote>
            <p><?php echo $bleh; ?> </p>
        </blockquote>
       
        <?php endforeach; ?>


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

Thanks guys!
ellypho
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Jul 05, 2012 7:43 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: http://phillipnb.wordpress.com/category/pdo-2/
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

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

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron