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 Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/ Share on other sites More sharing options...
Ch0cu3r Posted March 4, 2014 Share Posted March 4, 2014 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()); Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/#findComment-1471455 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 Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/#findComment-1471456 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' Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/#findComment-1471474 Share on other sites More sharing options...
Ch0cu3r Posted March 5, 2014 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; Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/#findComment-1471497 Share on other sites More sharing options...
williamh69 Posted March 5, 2014 Author Share Posted March 5, 2014 Thank you very much........ Link to comment https://forums.phpfreaks.com/topic/286701-dynamic-metatags-with-php-and-mysql/#findComment-1471539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.