Correct me if I wrong, but you're declaring $id AFTER binding the SQL parameter, therefore your :id isn't being bound to anything, hence the empty returned array. I think: $d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE publisher >> :id"); $id = 'DC Comics'; $d_series_fetch->bindParam(':id',$id); *should* work. >---- Original Message ---- >From: matty jones <urlugal@xxxxxxxxx> >To: php-general@xxxxxxxxxxxxx >Sent: Fri, Mar 25, 2011, 8:19 AM >Subject: possible variable declaration error > >I get the following error " PHP Notice: Undefined index: publisher in >/var/www/testfunctions.php on line 65" and I have narrowed it down to what I >*think* is a variable not being declared. Here is the code. > > >//this will fetch the data from a table >$d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE publisher >= :id"); >$d_series_fetch ->bindParam(':id', $id); >$id = 'DC Comics'; > > >if ($d_series_fetch ->execute(array($_GET['publisher']))) { >while ($row = $d_series_fetch -> fetch()) { >print_r($row); >} >} > >I have prepared statements to open a connection and insert data and they >work fine if I comment the preceding block out so I am fairly certain the >problem is in there somewhere. I am using the latest version of PHP and am >running Postgres8.4 as my db. If I use the isset() function and add an echo >(code below) I get no errors but the query still doesn't work so again I am >fairly certain that I am forgetting to declare something somewhere. > >//this will fetch the data from a table >$d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE publisher >= :id"); >$d_series_fetch ->bindParam(':id', $id); >$id = 'DC Comics'; > >$publisher = ''; > >if (isset($_GET['publisher'])) >{ > >if ($d_series_fetch ->execute(array($_GET['publisher']))) { >while ($row = $d_series_fetch -> fetch()) { >print_r($row); > >} >} >} > >else {echo"this didn't work";} > >$dbh = null; //close the database connection by setting the PDO object to >NULL > } > >I am fairly new to PHP and have very little idea on PDO's so this is most >likely a simple error(s) I know. >Thank > >Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php