williamh69 Posted March 4, 2014 Share Posted March 4, 2014 hi guys, i have this database table called meta_tags id keywords description title and I have the following code to retrieve the data <?php $id = 1; $query=("SELECT title, keywords, description FROM meta_tags WHERE id =$id"); $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $title= $row['title']; $keywords= $row['keywords']; $description= $row['description']; echo"<meta name='title' content='$title'>"; echo"<meta name='keywords' content='$keywords'>"; echo"<meta name='description' content='$description'>"; } ?> but I have this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\WHB\includes\metags.inc.php on line 10 can you guys help me please.... thank you Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 4, 2014 Share Posted March 4, 2014 (edited) That error usually means the query has failed, due to an error. Is that all your code? Are you connected to mysql? Use mysql_error to see what the error could be. $result=mysql_query($query) or trigger_error('DB error: ' . mysql_error()); Edited March 4, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
MadTechie Posted March 4, 2014 Share Posted March 4, 2014 As a guess you have missed the connection to mysql as mysql_fetch_array is getting a boolean (i assume false, that is an error in the query) try a result=mysql_query($query) or die(mysql_error()); and see what the error is Quote Link to comment Share on other sites More sharing options...
williamh69 Posted March 5, 2014 Author Share Posted March 5, 2014 hi guys, i change all the code: <?php $dbhost = 'localhost'; $dbuser = 'whbweb'; $dbpass = 'andres69'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } if (!isset($page_id)) $page_id=1; $sql = 'SELECT keywords,title,description FROM meta_tags where id=$page_id'; mysql_select_db('whb'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_assoc($retval)) { $title= $row['title']; $keywords= $row['keywords']; $description= $row['description']; echo"<meta name='title' content='$title'>"; echo"<p>"; echo"<meta name='keywords' content='$keywords'>"; echo"<p>"; echo"<meta name='description' content='$description'></br>"; } mysql_close($conn); ?> Now I have the following error: Could not get data: Unknown column '$page_id' in 'where clause' Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted March 5, 2014 Solution Share Posted March 5, 2014 $sql = 'SELECT keywords,title,description FROM meta_tags where id=$page_id'; Variables are not expanded in single quotes. Change id=$page_id'; to id='.$page_id; Quote Link to comment Share on other sites More sharing options...
williamh69 Posted March 5, 2014 Author Share Posted March 5, 2014 Thank you very much........ Quote Link to comment 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.