rocky48 Posted November 9, 2016 Share Posted November 9, 2016 (edited) I am trying to use some code which has com from the Larry Ullman book 'PHP 6 and MYSQL 5'. I think I have got the path wrong. Here is the error that has printed: An error occurred in script D:\wamp\www\LoginTest\register.php on line 10: require_once(MYSQL): failed to open stream: No such file or directoryDate/Time: 9-11-2016 15:24:59Array([_GET] => Array()[_POST] => Array([first_name] => Tony[last_name] => Hudson => t.e.hudson@btinternet.com[password1] => l45N0och[password2] => l45N0och[submit] => Register[submitted] => TRUE)[_COOKIE] => Array([phpSESSID] => ba2t1fa8tqut55teq427acjel2)[_SERVER] => Array([HTTP_HOST] => logintest[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[HTTP_ACCEPT_LANGUAGE] => en-GB,en;q=0.5[HTTP_ACCEPT_ENCODING] => gzip, deflate[HTTP_REFERER] => http://logintest/register.php[HTTP_COOKIE] => PHPSESSID=ba2t1fa8tqut55teq427acjel2[HTTP_CONNECTION] => keep-alive[HTTP_UPGRADE_INSECURE_REQUESTS] => 1[CONTENT_TYPE] => application/x-www-form-urlencoded[CONTENT_LENGTH] => 135[PATH] => C:\Program Files (x86)\ActiveState Komodo Edit 7\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShel l\v1.0\;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\Program Files\Intel\Intel® Management Engine Components\IPT;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\Doctrine extensions for PHP\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\Windows Apps[systemRoot] => C:\WINDOWS[COMSPEC] => C:\WINDOWS\system32\cmd.exe[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC[WINDIR] => C:\WINDOWS[sERVER_SIGNATURE] =>Apache/2.4.23 (Win64) PHP/7.0.10 Server at logintest Port 80[sERVER_SOFTWARE] => Apache/2.4.23 (Win64) PHP/7.0.10[sERVER_NAME] => logintest[sERVER_ADDR] => ::1[sERVER_PORT] => 80[REMOTE_ADDR] => ::1[DOCUMENT_ROOT] => D:/wamp/www/LoginTest[REQUEST_SCHEME] => http[CONTEXT_PREFIX] =>[CONTEXT_DOCUMENT_ROOT] => D:/wamp/www/LoginTest[sERVER_ADMIN] => wampserver@wampserver.invalid[sCRIPT_FILENAME] => D:/wamp/www/LoginTest/register.php[REMOTE_PORT] => 56771[GATEWAY_INTERFACE] => CGI/1.1[sERVER_PROTOCOL] => HTTP/1.1[REQUEST_METHOD] => POST[QUERY_STRING] =>[REQUEST_URI] => /register.php[sCRIPT_NAME] => /register.php[php_SELF] => /register.php[REQUEST_TIME_FLOAT] => 1478705099.476[REQUEST_TIME] => 1478705099)[_ENV] => Array()[_REQUEST] => Array([first_name] => Tony[last_name] => Hudson => t.e.hudson@btinternet.com[password1] => l45N0och[password2] => l45N0och[submit] => Register[submitted] => TRUE)[_FILES] => Array()[page_title] => Register[_SESSION] => Array())( ! ) Fatal error: require_once(): Failed opening required 'MYSQL' (include_path='. :\wamp\www\LoginTest\includes') in D:\wamp\www\LoginTest\register.php on line 10Call Stack# Time Memory Function Location1 0.0004 386824 {main}( ) ...\register.php:0 Here is the Config.inc.php file that includes the file: <?php # Script 16.3 - config.inc.php /* This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ // Document who created this site, when, why, etc. // ********************************** // // ************ SETTINGS ************ // // Flag variable for site status: define('LIVE', FALSE); // Admin contact address: define('EMAIL', 't.e.hudson@btinternet.com'); // Site URL (base for all redirections): define ('BASE_URL', 'http://localhost/'); // Location of the MySQL connection script: define ('MYSQL', 'D:\wamp\www\\'); // Adjust the time zone for PHP 5.1 and greater: date_default_timezone_set("Europe/London"); // ************ SETTINGS ************ // // ********************************** // // ****************************************** // // ************ ERROR MANAGEMENT ************ // // Create the error handler: function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message. $message = "<p>An error occurred in script $e_file on line $e_line: $e_message\n<br />"; // Add the date and time: $message .= "Date/Time: " . date("j-n-Y H:i:s") . "\n<br />"; // Append $e_vars to the $message: $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { // Development (print the error). echo '<div class ="error">' . $message . '</div><br />'; } else { // Do not show the error: // Send an email to the admin: mail(EMAIL, 'Site Error!', $message, 'From: email@example.com'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. } // End of my_error_handler() definition. // Use my error handler. set_error_handler ('my_error_handler'); // ************ ERROR MANAGEMENT ************ // // ****************************************** // ?> Is it the way I have written the path?Should it be relative to the root folder?I am using WAMP. In the book I am using it says that it should be in the same folder as htdocs, but does this equate to the www folder on WAMP?It is not opening the MySQL database. I have run the connection script and it does connect to the database. Here is the registration script: <?php # Script 16.6 - register.php // This is the registration page for the site. require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once('MYSQL'); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: admin@sitename.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="register.php" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?> Your help would be appreciated! Edited November 9, 2016 by rocky48 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 9, 2016 Share Posted November 9, 2016 (edited) What's with the 3 slashes?? And - you are trying to include a script with that require statement but you aren't specifying anything except an attempt at a path. Edited November 9, 2016 by ginerjm Quote Link to comment Share on other sites More sharing options...
rocky48 Posted November 9, 2016 Author Share Posted November 9, 2016 A copying error! The one I ran only had 2 slashes! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 9, 2016 Share Posted November 9, 2016 (edited) Alright - so now you have fixed it, but did you add a script name for that require? And why do you use 1 slash twice and end it with 2? Edited November 9, 2016 by ginerjm Quote Link to comment Share on other sites More sharing options...
rocky48 Posted November 9, 2016 Author Share Posted November 9, 2016 Right Tried this, but still the same error: // Location of the MySQL connection script:define ('MYSQL', 'D:\wamp\www\Connect_login.php\\'); Without the second slash it errors on line 50. This was pointed out to me on another forum. Am I right in assuming that htdocs is equivalent to www in WAMP? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 9, 2016 Share Posted November 9, 2016 (edited) How about this define('MYSQL','d:\wamp\www\'); .. .. .. require(MYSQL.'Connect_login.php'); Never used a define so I may have it a bit wrong, but you can see how mine is different than yours. Edited November 9, 2016 by ginerjm Quote Link to comment Share on other sites More sharing options...
rocky48 Posted November 9, 2016 Author Share Posted November 9, 2016 Little confused! What script are you refering to? config.inc.php? Require INSTEAD of Define? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 9, 2016 Share Posted November 9, 2016 Use forward slashes. It saves having to worry about escaping backslashes (and quotes) and it's fine on Windows as well as Linux. define('MYSQL','d:/wamp/www/'); 1 Quote Link to comment Share on other sites More sharing options...
rocky48 Posted November 9, 2016 Author Share Posted November 9, 2016 I have admitted defeat and taken the easier option: Changed: require_once('MYSQL'); to require_once('includes/Connect_login.php'); Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted November 9, 2016 Solution Share Posted November 9, 2016 define creates constants which you reference without quotes elsewhere in the script, such as: require(MYSQL); You would have to define your MYSQL constant to include the specific file you need however, or concatenate it to the constant in the require, as you cannot require an entire directory. define('MYSQL', 'd:/wamp\www/includes/Connect_login.php'); Quote Link to comment 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.