www.webdeveloper.com
Results 1 to 2 of 2

Thread: Meta tags from a database

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    23

    Meta tags from a database

    Okay this is what I have so far, will this work or not.

    At the moment I get an error message saying "no database selected".

    I have called the db - "mydb" and the table "url"

    PHP Code:
    <?php 
    $localhost 
    'localhost';
    $dbuser 'root';
    $dbpass 'password';
    $dbname 'mydb';

    $connect mysql_connect($localhost$dbuser$dbpass);
    mysql_select_db('dbname'$connect);

    $page = array('about','profiles','another_page');

    $page = isset($_GET['page']) ? $_GET['page'] : 'home';

    $sql mysql_query("SELECT * FROM mydb WHERE id = '" $page "' LIMIT 1") or die (mysql_error()); 

    if( 
    mysql_num_rows($sql) ) {
    $row mysql_fetch_array($sql);
    $title $row['title']; // get title from database
    $description $row['description']; // get description from database
    $keywords substr($row['keywords'], 0250); // get keywords (250 characters) from database
    } else {
    $title 'Set Default Title';
    $description 'Set Default Description';
    $keywords 'Set Default Keywords';



    include(
    $_SERVER['DOCUMENT_ROOT']. '/include/header.php');  

    include(
    'content/'.$page.'.php'); 

    include(
    $_SERVER['DOCUMENT_ROOT']. "/include/footer.php");
    ?>
    contents of my header.php

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title><?php echo $title?></title>
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    <meta http-equiv="Content-Language" content="en">
    <meta name="description" content="<?php echo $description?>">
    <meta name="keywords" content="<?php echo $keywords?>">
    </head>
    <body>

    <!-- HTML content goes here... -->

    </body>
    </html>

  2. #2
    Join Date
    Apr 2012
    Posts
    23
    Cancel that, I fixed it and it works perfect:

    changed mysql_select_db('dbname', $connect); to:

    mysql_select_db($dbname, $connect);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles