AbydosGater Posted November 4, 2006 Share Posted November 4, 2006 Hi, This script runs fine and dandy on my hosting account, but i just installed apache and php5 with mysql5 or something, not sure about versions,In my logout.php i have the following...[code]session_start();$handle = $_SESSION['handle'];$ip = $_SESSION['ip'];session_destroy();require("config.php");dbconnect();mysql_query("INSERT INTO chat_messages (message_id, member_id, handle, ip, timestamp, message, type) VALUES (NULL , '0', '$handle', '$ip', CURRENT_TIMESTAMP , '$handle has just logged out of chat', 'users') ") or die(mysql_error());echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=http://localhost/\">";echo "<center><b>Thank you for logging out!<br><br>Your chat session has ended!</b></center>";exit;[/code]But when i run the page, it exits at dbconnect(); so i had a look at my error logs and it says..[quote][04-Nov-2006 12:32:40] PHP Fatal error: Cannot redeclare dbconnect() (previously declared in C:\apache2triad\htdocs\agc\members\chat\common.php:9) in C:\apache2triad\htdocs\agc\members\chat\common.php on line 13[/quote]But im not redeclaring it! im only running the function!?Any idea why im getting this error, or how to fix it?Abydos Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/ Share on other sites More sharing options...
sinisake Posted November 4, 2006 Share Posted November 4, 2006 whats in your config.php? Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119568 Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 It just has my db variables and then includes the common.phpand in the common.php has.....function dbconnect(){ global $dbhost, $dbuname, $dbpass, $dbname; mysql_connect("$dbhost", "$dbuname", "$dbpass") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error());};Anyone any idea? Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119570 Share on other sites More sharing options...
wildteen88 Posted November 4, 2006 Share Posted November 4, 2006 [quote author=AbydosGater link=topic=113828.msg462859#msg462859 date=1162645551]It just has my db variables and then includes the common.phpand in the common.php has.....function dbconnect(){ global $dbhost, $dbuname, $dbpass, $dbname; mysql_connect("$dbhost", "$dbuname", "$dbpass") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error());};Anyone any idea?[/quote]dbconnect is a nbuiltin function in PHP. You'll want to change the name of your defined function dbconnect to sometyhing like db_connect or dbconn instead. In the following code:[code]function dbconnect(){ global $dbhost, $dbuname, $dbpass, $dbname; mysql_connect("$dbhost", "$dbuname", "$dbpass") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error());};[/code]You are redefining the dbconnect function which you cannot do. Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119572 Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 Ah kk i no whats happening i will change it now! Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119573 Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 It wasnt that! i even tryed changing to conn_andy() and no luck, but i found the problem, i wads requiring the config.php twice which ment the function was declaring twice:PAll fixed Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119575 Share on other sites More sharing options...
wildteen88 Posted November 4, 2006 Share Posted November 4, 2006 I see. In that you'll want to use require_once instead of require Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119578 Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 oh ok, didnt think of that thanks! Quote Link to comment https://forums.phpfreaks.com/topic/26151-my-function-is-trying-to-declare-when-it-should-run/#findComment-119594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.