Jump to content

Can't find file?


Go to solution Solved by kicken,

Recommended Posts

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 directory
Date/Time: 9-11-2016 15:24:59

Array
(
[_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='. ;D:\wamp\www\LoginTest\includes') in D:\wamp\www\LoginTest\register.php on line 10
Call Stack
# Time Memory Function Location
1 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 by rocky48
Link to comment
https://forums.phpfreaks.com/topic/302499-cant-find-file/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/302499-cant-find-file/#findComment-1539142
Share on other sites

  • Solution

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');
Link to comment
https://forums.phpfreaks.com/topic/302499-cant-find-file/#findComment-1539162
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.