shaunmacie Posted April 5, 2007 Share Posted April 5, 2007 I am trying to setup a quick simple easy username and password login using MySQL and PHP. This is my first experience with MySQL and my second with PHP. I have the login working when I test it locally in a .php file that has the .php code and the form field data in dreamweaver, but it doesn't work when I put the files live. I put the form code in a separate file: http://www.dofaux.com/logintest.html that posts to my .php file, and here's the error I get: Warning: main(Connections/users.php): failed to open stream: No such file or directory in /home/dofaux/public_html/login2.php on line 1 Fatal error: main(): Failed opening required 'Connections/users.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dofaux/public_html/login2.php on line 1 I am setting it up in dreamweaver and I think I just have a problem with absolute file paths, but I don't know what to fix (the dreamweaver MYSQL connection option for the MySQL server is set to 'localhost' because I couldn't figure out anything else that worked.) Basically, I think I just need to know how to direct it to my database files when live. Here is the code in my .php file: <?php require_once('Connections/users.php'); ?> <?php // *** Validate request to login to this site. session_start(); $loginFormAction = $_SERVER['PHP_SELF']; if (isset($accesscheck)) { $GLOBALS['PrevUrl'] = $accesscheck; session_register('PrevUrl'); } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "http://www.dofaux.com/salonshop.html"; $MM_redirectLoginFailed = "http://www.dofaux.com/salon.html"; $MM_redirecttoReferrer = false; mysql_select_db($database_users, $users); $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $users) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_Username"); session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> Should it be done a better way (should the .php code and the form data be on the same page). This works when I do a preview in dreamweaver but doesn't when the file is live: <?php require_once('Connections/users.php'); ?> <?php // *** Validate request to login to this site. session_start(); $loginFormAction = $_SERVER['PHP_SELF']; if (isset($accesscheck)) { $GLOBALS['PrevUrl'] = $accesscheck; session_register('PrevUrl'); } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "http://www.dofaux.com/salonshop.html"; $MM_redirectLoginFailed = "http://www.dofaux.com/salon.html"; $MM_redirecttoReferrer = false; mysql_select_db($database_users, $users); $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $users) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_Username"); session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div align="center"> <form name="form1" method="POST" action="<?php echo $loginFormAction; ?>"> <table width="400" border="0" cellspacing="0" cellpadding="3"> <tr> <td width="100">Username:</td> <td><input name="username" type="text" id="username"></td> </tr> <tr> <td width="100">Password:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td width="100"> </td> <td><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </div> </body> </html> Any help for this database novice would be great! Thanks, Shaun Link to comment https://forums.phpfreaks.com/topic/45654-php-and-mysql-login-page-help/ Share on other sites More sharing options...
lpeek Posted May 1, 2007 Share Posted May 1, 2007 Well from what its telling us... 'No such file or directory in /home/dofaux/public_html/login2.php on line 1' look at line one... the code is: <?php require_once('Connections/users.php'); ?> and it says 'no such file or directory' so im guessing the file 'Connections/users.php' doesnt actually exist? that would really be the only reason you get this error i think... if you're sure it does exist just try putting the WHOLE url in there instead of just 'Connections/users.php'. see if it works then... so maybe 'http://www.mysite.com/Connections/users.php' Link to comment https://forums.phpfreaks.com/topic/45654-php-and-mysql-login-page-help/#findComment-242690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.