在PHP的CMS主页

I am working on something it has 2 pages. One is index.php and another one is admin.php.I am making CMS page where you can edit information on the page yourself. Then it will go to the database, where the information is stored. I also have to have it where the user can update the information on the page. I am getting a little bit confused here.For instance here I am calling the database and I am starting a function called get_content:

<?php
function dbConnect(){

$hostname="localhost";
$database="blank";
$mysql_login="blank";
$mysql_password="blank";

 if(!($db=mysql_connect($hostname, $mysql_login, $mysql_password))){
    echo"error on connect";
 }
 else{
    if(!(mysql_select_db($database,$db))){
        echo mysql_error();
        echo "<br />error on database connection. Check your settings.";
    }
    else{

        return $db;
        }

}

function get_content(){

$sql = "Select PageID,PageHeading,SubHeading,PageTitle,MetaDescription,MetaKeywords From tblContent ";
$query = mysql_query($sql) or die(mysql_error());
while ($row =mysql_fetch_assoc($query,MYSQL_ASSOC)){
$title =$row['PageID'[;
$PageHeading =$row['PageHeading'];
$SubHeading = $row['SubHeading'];
$PageTitle = $row['PageTitle'];
$MetaDescription =$row['MetaDescription'];
$MetaKeywords = $row['MetaKeywords'];


 ?>

And then on the index page and I am going to echo it out in the spot that someone can change:

<h2><a href = "admin.php"><?php echo mysql_result($row,0,"SubHeading");?>A Valid XHTML and CSS Web Design by WG.</a></h2>

I do know that the function is not finished I am still working on that part. What I am wondering is am I echoing it out right or I am way off. This is my first time messing with CMS in php and I am still learning it. I am working with navicat and text pad on this, yes I know it is old school but that is what I am being shown with. But my index is a form not a blog. I have seen many of CMS pages for blogs not to many to be used with forms. Any input will be considered thanks for reading my question.

Your question is a bit confusing and your code very incomplete. I'ts hard to say if you do it the right way since I don't see the rest of the script. You need to connect to the database there as well and get your data. The $row variable only exists in the while statement inside you function get_content() though.

You could complete the get_content() and use it in the index.php as well. Remember that the variables you define inside a function only is available there though. If you need the data outside that function you need to return the values you need and save them to some other variable there. Put if you do the same as you've started doing in the get_content() function in index.php, then you just have to echo the variables you define. Like this:

<h2><a href="admin.php"><?php echo $SubHeading; ?></a></h2>

or you could also do it like this somewhere inside the php tags:

echo '<h2><a href="admin.php">{$SubHeading}</a></h2>';

I hope that answers your question.

EDIT: What you need in the index.php page is exactly what you seem to be doing in the admin file. You need to connect to db using mysql_connect() and select db with mysql_select_db(). You then need to select the data from the db using the appropriate query with $query = mysql_query($sql). If it's more then one row you want to display you need to put it in a while loop otherwise (which seems to be the case here) you just need to do one $row = mysql_fetch_assoc($query). After that you can get the data using $row['column_name']. If you have more than one row you can just use $row['column_name'] in side the while loop to get each consecutive row's data.

Here is an example index.php:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password') or
        die('Could not connect: ' . mysql_error());

mysql_select_db('database_name')) or die('Could not select database: ' .
        mysql_error());

$sql = "SELECT SubHeading FROM tblContent WHERE PageID='1' LIMIT 1;";
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);

echo '<h2><a href="admin.php">{$row[\'SubHeading\']}</a></h2>';

mysql_close();
?>

This is just what you need to display the SubHeading from you database. You probably also need to handle your form and save the submitted data to the database in your admin.php file.