vet911 Posted August 14, 2015 Share Posted August 14, 2015 I'm getting this error message after changing the $hostname given to me from Godaddy. It lists line 68 as the error: this is the code section $result = $dbh->query($sql); Any help would be appreciated. <?php try { $type = $_GET['type']; //-query the database table if($_GET['type'] == 'ak') { //*$sql = "SELECT * FROM jewelry WHERE class = '$type' ";**/ $sql = "SELECT id, cid, group, image_th, image, picture, comment FROM images WHERE group = 'dionne' ORDER BY cid ASC"; } else if($_GET['type'] == 'dionne') { $sql = "SELECT * FROM images WHERE picture = '2'"; } $result = $dbh->query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/ Share on other sites More sharing options...
requinix Posted August 14, 2015 Share Posted August 14, 2015 Not sure what a hostname has to do with any of that code... How about posting the rest of it? Be sure to include the bit where $dbh gets defined. Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518742 Share on other sites More sharing options...
vet911 Posted August 14, 2015 Author Share Posted August 14, 2015 I have included most of the code from the beginning. <?php try { { /*** mysql hostname ***/ $hostname = 'xxxxxxxxxxxxxxxxxxxxx'; /*** mysql username ***/ $username = 'xxxxxxxxxx'; /*** mysql password ***/ $password = 'xxxxxxxxx'; $dbname = 'xxxxxx'; $dhb = null; $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true ); /** echo a message saying we have connected **/ /**echo "connected"; **/ } } catch(PDOException $e) { echo $e->getMessage(); } ?> <div class="content"> <?php include('header.php');?> <?php include('menu1.php');?> <br /> <div> <center><table cellspacing="5" cellpadding="5" width="800" border="0"> <tr> <td height="57" colspan="3" width="800"> <hr /> <div style="text-align: center;">Multiuse Pictures 2014</div> <div style="text-align: center;">Click picture to enlarge.</div> <hr /> </td> </tr> <?php try { $type = $_GET['type']; //-query the database table if($_GET['type'] == 'ak') { //*$sql = "SELECT * FROM jewelry WHERE class = '$type' ";**/ $sql = "SELECT id, cid, group, image_th, image, picture, comment FROM images WHERE group = 'dionne' ORDER BY cid ASC"; } else if($_GET['type'] == 'dionne') { $sql = "SELECT * FROM images WHERE picture = '2'"; } $result = $dbh->query($sql); $rows2 = '0'; $rows3 = '0'; if($result) { $i = 0; $max_columns = 3; foreach ($result as $row) { // open row if counter is zero if($i == 0) { echo "<tr VALIGN='top'>"; } // if ($row['avail'] != "0") //{ // make sure we have a valid product ALIGN='CENTER' if($row['image_th'] != "" && $row['image_th'] != null) { Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518768 Share on other sites More sharing options...
requinix Posted August 14, 2015 Share Posted August 14, 2015 You've got a try/catch up there at the top that will show an error message if PDO had a problem. Was there an error? Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518771 Share on other sites More sharing options...
vet911 Posted August 14, 2015 Author Share Posted August 14, 2015 Here is the error code: Fatal error: Call to a member function query() on a non-object in <b>/home/content/r/i/g/rigtway/html/site_1.php on line 68 Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518780 Share on other sites More sharing options...
vet911 Posted August 14, 2015 Author Share Posted August 14, 2015 Image of website error! Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518786 Share on other sites More sharing options...
scootstah Posted August 14, 2015 Share Posted August 14, 2015 Look at the top. Your database connection is failing with the credentials that you have used. Quote Link to comment https://forums.phpfreaks.com/topic/297773-fatal-error-call-to-a-member-function-query-on-a-non-object/#findComment-1518788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.