I decided to make the mysql query thing into a funciton on another file instead of having the mqsql_connect thing in all of the other functions
For this website:
[url]http://games-host.co.cc[/url]
Error:
[code]Cannot redeclare SQL_user_assoc() (previously declared in G:\Programs\Portable\xampplite\htdocs\GamesHost\db.php:4) in G:\Programs\Portable\xampplite\htdocs\GamesHost\db.php on line 9[/code]
File 1 [db.php]
[php]
<?php
include 'db_data.php';
include_once 'DBnorm.php';
function SQL_user_assoc($username)
{
$sql = DB("SELECT * FROM users WHERE username = '$username'");
return mysql_fetch_array($sql,SQL_ASSOC);
}
function SQL_insert($username,$password)
{
DB("INSERT INTO users (username,password) values('$username','$password')");
}
function onlinestats($user,$IO)
{
DB("UPDATE users SET online = '$IO' WHERE username = '$user'");
}
function get_users($where,$data)
{
return DB("SELECT * FROM users WHERE $where = '$data'");
}
?>
[/php]
File 2 [DBnorm.php]
[php]
<?php
include 'db_data.php';
function DB($str) {
global $sql_host,$sql_user,$sql_password,$sql_db;
$link = mysql_connect("$sql_host","$sql_user","$sql_password")or die("cannot connect");
mysql_select_db($sql_db);
return mysql_query("$str");
mysql_close($link);
}
?>
[/php]
Any ideas? Thanks Kieran
you're including a file that includes that same file
use require_once()
[editline]13th November 2010[/editline]
or just fix it altogether
[QUOTE=TehWhale;26037620]you're including a file that includes that same file
use require_once()
[editline]13th November 2010[/editline]
or just fix it altogether[/QUOTE]
whats that supposed to mean?
[code]
Fatal error: Cannot redeclare DB() (previously declared in G:\Programs\Portable\xampplite\htdocs\GamesHost\DBnorm.php:4) in G:\Programs\Portable\xampplite\htdocs\GamesHost\DBnorm.php on line 13
[/code]
Thanks
Remove "include 'db_data.php';" from File 2 [DBnorm.php]
[QUOTE=TehWhale;26037773]Remove "include 'db_data.php';" from File 2 [DBnorm.php][/QUOTE]
thats where the database login details are stored, i removed it from the other one its not needed there
include_once()
Yes, but you already have them called from the other file.
You're basically doing this:
[php]<?php
include 'db_data.php';
<?php
include 'db_data.php';
function DB($str) {
global $sql_host,$sql_user,$sql_password,$sql_db;
$link = mysql_connect("$sql_host","$sql_user","$sql_password")or die("cannot connect");
mysql_select_db($sql_db);
return mysql_query("$str");
mysql_close($link);
}
?>
function SQL_user_assoc($username)
{
$sql = DB("SELECT * FROM users WHERE username = '$username'");
return mysql_fetch_array($sql,SQL_ASSOC);
}
function SQL_insert($username,$password)
{
DB("INSERT INTO users (username,password) values('$username','$password')");
}
function onlinestats($user,$IO)
{
DB("UPDATE users SET online = '$IO' WHERE username = '$user'");
}
function get_users($where,$data)
{
return DB("SELECT * FROM users WHERE $where = '$data'");
}
?>[/php]
Over, and over
its been removed from db.php so shouldnt that stop it being included twice?
Sorry, you need to Log In to post a reply to this thread.