Jump to content

dynamic metatags with php and mysql


williamh69

Recommended Posts

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

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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.