rscott7706 Posted May 23, 2006 Share Posted May 23, 2006 OK folks, I am trying hard not to bother you all with every glitch I hit. It is up to me to learn this stuff and solve my own problems. But, sometimesthe wind don't blow, and the grass don't grow... (line from Little Big Man - old movie).I have worked on a problem for hours now, and think it may not be me, but the differencebetween PHP4 (which my server is running) and the coding I have (PHP5)... I THINK!! Not sure.The crash is at line 39 - dbConnect("egcaorga_mgt");Messge:Fatal error: Call to undefined function: dbconnect() in/home/egcaorga/public_html/new_site/accesscontrol/accesscontrol.php on line 39This seems to be a PHP 5 command. Am I going in the right direction? If so, is there anequivalent PHP 4 command?Here is the code:<?php // accesscontrol.phpinclude_once 'common.php';include_once 'db.php';session_start();$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid'];$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];if(!isset($uid)) { ?> <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Please Log In for Access </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1> Login Required </h1> <p>You must log in to access this area of the site. If you are not a registered user, <a href="signup.php">click here</a> to sign up for instant access!</p> <p><form method="post" action="<?=$_SERVER['PHP_SELF']?>"> User ID: <input type="text" name="uid" size="8" /><br /> Password: <input type="password" name="pwd" SIZE="8" /><br /> <input type="submit" value="Log in" /> </form></p> </body> </html> <?php exit;}$_SESSION['uid'] = $uid;$_SESSION['pwd'] = $pwd;dbConnect("egcaorga_mgt");$sql = "SELECT * FROM user WHERE userid = '$uid' AND password = PASSWORD('$pwd')";$result = mysql_query($sql);if (!$result) { error('A database error occurred while checking your '. 'login details.\\nIf this error persists, please '. 'contact admin@egca.org.');}if (mysql_num_rows($result) == 0) { unset($_SESSION['uid']); unset($_SESSION['pwd']); ?> <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Access Denied </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1> Access Denied </h1> <p>Your user ID or password is incorrect, or you are not a registered user on this site. To try logging in again, click <a href="<?=$_SERVER['PHP_SELF']?>">here</a>. To register for instant access, click <a href="signup.php">here</a>.</p> </body> </html> <?php exit;}$username = mysql_result($result,0,'fullname');?>Thanks in advance... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/ Share on other sites More sharing options...
ryanlwh Posted May 23, 2006 Share Posted May 23, 2006 it sounds like a funtion defined in the included "db.php". can you show us db.php? Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38304 Share on other sites More sharing options...
rscott7706 Posted May 23, 2006 Author Share Posted May 23, 2006 [!--quoteo(post=376398:date=May 23 2006, 10:16 AM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ May 23 2006, 10:16 AM) [snapback]376398[/snapback][/div][div class=\'quotemain\'][!--quotec--]it sounds like a funtion defined in the included "db.php". can you show us db.php?[/quote]Sure - with password deleted of course...<?php // db.phpmysql_connect("localhost","egcaorga_rscott","");mysql_select_db("egcaorga_mgt");?> Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38307 Share on other sites More sharing options...
ryanlwh Posted May 23, 2006 Share Posted May 23, 2006 well, in this case dbConnect is not even needed... Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38312 Share on other sites More sharing options...
wildteen88 Posted May 23, 2006 Share Posted May 23, 2006 Umm, dbConnect is a non-existant defined function within PHP. But is more likely to be a user definied function instead. From looking at your code dbConnect isn't needed at all. So remove it from your code and you should be fine. Unless its defined in common.php as thats another file you are including. Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38319 Share on other sites More sharing options...
rscott7706 Posted May 23, 2006 Author Share Posted May 23, 2006 [!--quoteo(post=376407:date=May 23 2006, 10:32 AM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ May 23 2006, 10:32 AM) [snapback]376407[/snapback][/div][div class=\'quotemain\'][!--quotec--]well, in this case dbConnect is not even needed...[/quote]I would tend to agree with you, but it is specifically in the script. Look at it here:[a href=\"http://www.sitepoint.com/article/users-php-sessions-mysql/5\" target=\"_blank\"]http://www.sitepoint.com/article/users-php-sessions-mysql/5[/a]I previously thought that may be the problem before and took it out, but it crashed worse (if there is a "worse"). I also tried coding it with my database logon stuff in this file instead of the include db.php - no change - same error code.I am dumfounded that all these scripts that are supposed to be simple and straighforward seem to crash.I tried Crayon Violent's one at:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=92613&st=0&p=370773entry370773\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...73entry370773[/a]It gives me a:Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/egcaorga/public_html/new_site/accesscontrol/access/authenticate.php:9) in /home/egcaorga/public_html/new_site/accesscontrol/access/authenticate.php on line 10Err:Query Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38322 Share on other sites More sharing options...
wildteen88 Posted May 23, 2006 Share Posted May 23, 2006 Looks like you may have missread the tutorial. Look on this page [a href=\"http://www.sitepoint.com/article/users-php-sessions-mysql/3\" target=\"_blank\"]here[/a] at the first block of PHP code. Notice they have defined their own function called dbConnect in db.phpIf you copy the code they have used for db.php into your db.php all should be fine.About the session error make sure you have place your code in the correct place and that you have followed the tutorial correctly too by reading through the tutorial again. Chances are you may have made a mistake somewhere along the line. Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38326 Share on other sites More sharing options...
rscott7706 Posted May 23, 2006 Author Share Posted May 23, 2006 Crud man... The db.php was an iteration I put up trying to make it work. Then I posted here mistakenly - not remembering I had changed the original.I went back to the original and it still crashes. I think I am just not analytical enoughfor this php stuff.I know I have looked it over several times, and everthing is (to my knowledge) exactly as it should be. But I know there is something I am missing. But I tire of myself and lackof skills here.Thnks for your help and patience with me... Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38338 Share on other sites More sharing options...
DapperDanMan Posted May 25, 2006 Share Posted May 25, 2006 Okay, I admit up front, I am new to php. But I swear I see some mistakes in the code?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php // accesscontrol.phpinclude_once 'common.php';include_once 'db.php';session_start();[/quote]I have always seen the include function with '(' and ')' around the included file. Is this something you don't need? Also, I have always placed my "session_start()" at the very top of the code. Now, the manual says if you are doing sessions with cookies it has to be this way, but could this be another problem perhaps?Please enlighten me, because I am very curious about these two things that I see.Thank you,DapperDanMan Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38777 Share on other sites More sharing options...
wildteen88 Posted May 25, 2006 Share Posted May 25, 2006 [!--quoteo(post=376885:date=May 25 2006, 05:00 AM:name=DapperDanMan)--][div class=\'quotetop\']QUOTE(DapperDanMan @ May 25 2006, 05:00 AM) [snapback]376885[/snapback][/div][div class=\'quotemain\'][!--quotec--]Okay, I admit up front, I am new to php. But I swear I see some mistakes in the code?I have always seen the include function with '(' and ')' around the included file. Is this something you don't need? Also, I have always placed my "session_start()" at the very top of the code. Now, the manual says if you are doing sessions with cookies it has to be this way, but could this be another problem perhaps?Please enlighten me, because I am very curious about these two things that I see.Thank you,DapperDanMan[/quote]when using inlcude or require you dont have to use the parentheses () around the file you are including, either of the following will work:[code]include("filename.php");include 'filename.php';include "filename.php";[/code]You can place session_start() whereever you want, BUT you must now have any output (text/html) to the browser before the use of session start(). For example this will cause an error:[code]<html>... html here ...<body><?phpsession_start();//rest of PHP here[/code]But this wont:[code]<?phpsession_start();?><html>... html here ...<body><?php//rest of PHP here[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10279-dbconnect/#findComment-38895 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.