Page 1 of 1

Error on the end tag?

Posted: Wed Mar 03, 2010 12:58 am
by akiwiguy
PHP is complaining about a parse error on line 71. The contents of that line is:

Code: Select all

?>
The whole file is below:

Code: Select all

<?php
// mysql includes
// define mysql database parameters
    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_DATABASE', 'cms');
 
//start_sql()
//sets up the sql database for use
//returns nothing
function start_sql() {
//Array to store validation errors
$errmsg_arr = array();
    
//Validation error flag
$errflag = false;
    
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
}
    
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
};
 
//getconfig($configname)
//returns the value of the config name specified from the database
function getconfig($configname) {
//Create query
$qry="SELECT * FROM config WHERE name=$configname";
$result=mysql_query($qry);
    
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) == 1) {
            $res1 = mysql_fetch_assoc($result);
            return $res1['value'];
            exit();
        } else {
            return 1;
        }
    }else {
        die("Query failed");
    }
};
 
//getpage($page_id)
//returns the mysql row of the page id specified
function getpage($page_id) {
//Create query
$qry="SELECT * FROM config WHERE name=$configname";
$result=mysql_query($qry);
    
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) == 1) {
            return $result;
            exit();
        } else {
            return 1;
        }
    }else {
        die("Query failed");
    }
};
?>

Re: Error on the end tag?

Posted: Wed Mar 03, 2010 1:14 am
by davex
Hi,

Hard to tell with your identation etc but for a starter it looks like you're not closing the function start_sql(). The reason the error is at the end is it gets there expecting to find something like a close brace and doesn't.

Cheers,

Dave.

Re: Error on the end tag?

Posted: Wed Mar 03, 2010 1:25 am
by akiwiguy
Oops. I forgot that close brace! But now, it comes up with this:

Code: Select all

Fatal error: Cannot redeclare start_sql() (previously declared in C:\wamp\www\cms\includes\mysql.inc.php:14) in C:\wamp\www\cms\includes\mysql.inc.php on line 30
:banghead:
Any ideas?

Re: Error on the end tag?

Posted: Wed Mar 03, 2010 2:42 am
by jraede
Apparently start_sql() is a function already used/declared by your MySQL library. Just change the name of your function and you should be fine.