Jump to content

Recommended Posts

I'm trying to get my register.php form on this page to submit the data to the database.  I'm getting the following error message:

 

[Warning:  require_once(../mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\register.php on line 46

 

Fatal error:  require_once() [function.require]: Failed opening required '../mysql_connect.php' (include_path='.;C:\php5\pear') in C:\wamp\www\register.php on line 46/quote]

 

Here is the script:

 

 

[<?php # Script 7.3 - register.php

$page_title = 'Register';
include ('./header.html');

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

$errors = array(); // Initialize error array.

// Check for a first name.
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = trim($_POST['first_name']);
}

// Check for a last name.
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$in = trim($_POST['last_name']);
}

// Check for an email address.
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = trim($_POST['email']);
}

// Check for a password and match against the confirm password.
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = trim($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password.';
}

if (empty($errors)) { // If everythings okay.

// Register the user in the database.
require_once ('../mysql_connect.php'); // Connect to the db.

// Make the query.
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW () )";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.

// Send an email, if desired.

// Print a message.
echo '<h1 id="mainhead">Thank you!</h1>
<p>You are now registered.  In Chapter 9 you will actually be able to log in!</p><p><br/></p>';

// Include the footer and quit the script (to not show the form).
include ('./footer.html');
exit();

} else { // If it did not run OK.
echo '<h1 id="mainhead">System Error</h1>
<p class="error">You could not be registered due to a system error.  We apologize for any inconvenience.</p>'; // Public message.
echo '<p>' . mysql_error() . '<br/><br/>Query: ' . $query . '</p>'; // Debugging message.
include ('./footer.html');
exit();
}

mysql_close(); // Close the database connection.

} else { // Report errors.

echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br/>';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br/>\n";
}
echo '</p><p>Please try again</p><p><br/></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="40" value"<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./footer.html');
?>/code]

Link to comment
https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/
Share on other sites

did you read the error message

failed to open stream: No such file or directory in

 

That means that whereever your require string is pointing, the file doesn't exist. verify that the file you are trying to include is located where you expect it to be included

did you read the error message

failed to open stream: No such file or directory in

 

That means that whereever your require string is pointing, the file doesn't exist. verify that the file you are trying to include is located where you expect it to be included

 

I thought it was suppose to be in C:\wamp\www\mysql_connect.php  ?  Along with the rest of my files.  I use a program called WAMPSERVER and it stores everything in the (www) folder.  Not htdocs .

 

I just looked in C:\wamp\www\ and the mysql_connect.php  is there. 

If register.php and mysql_connect.php is located in the same folder try changing the following line in register.php:

 

<?php
// Register the user in the database.
require_once ('../mysql_connect.php'); // Connect to the db.
?>

 

To this:

 

<?php
// Register the user in the database.
require_once ('mysql_connect.php'); // Connect to the db.
?>

If register.php and mysql_connect.php is located in the same folder try changing the following line in register.php:

 

<?php
// Register the user in the database.
require_once ('../mysql_connect.php'); // Connect to the db.
?>

 

To this:

 

<?php
// Register the user in the database.
require_once ('mysql_connect.php'); // Connect to the db.
?>

 

Thank you!  That took care of that error.  I found another error and I fixed it on my own.  I had (  i ) and ( l ) reversed.

 

However,  now I'm not getting any notices, or php errors on any specific lines --  "I AM"  getting this:

 

System ErrorYou could not be registered due to a system error.  We apologize for any inconvenience.

Access denied for user 'SYSTEM'@'localhost' (using password: NO)

 

Query:INSERT INTO users (first_name, last_name, email, password,registration_date) VALUES ('Brenton', 'Hale', 'RacerJM05@aol.com',SHA('ss'), NOW() )


 

Here is the updated code:

 

[<?php # Script 7.3 - register.php

$page_title = 'Register';
include ('./header.html');

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

$errors = array(); // Initialize error array.

// Check for a first name.
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = trim($_POST['first_name']);
}

// Check for a last name.
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = trim($_POST['last_name']);
}

// Check for an email address.
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = trim($_POST['email']);
}

// Check for a password and match against the confirm password.
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = trim($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password.';
}

if (empty($errors)) { // If everythings okay.

// Register the user in the database.
require_once ('mysql_connect.php'); // Connect to the db.

// Make the query.
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.

// Send an email, if desired.

// Print a message.
echo '<h1 id="mainhead">Thank you!</h1>
<p>You are now registered.  In Chapter 9 you will actually be able to log in!</p><p><br/></p>';

// Include the footer and quit the script (to not show the form).
include ('./footer.html');
exit();

} else { // If it did not run OK.
echo '<h1 id="mainhead">System Error</h1>
<p class="error">You could not be registered due to a system error.  We apologize for any inconvenience.</p>'; // Public message.
echo '<p>' . mysql_error() . '<br/><br/>Query: ' . $query . '</p>'; // Debugging message.
include ('./footer.html');
exit();
}

mysql_close(); // Close the database connection.

} else { // Report errors.

echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br/>';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br/>\n";
}
echo '</p><p>Please try again</p><p><br/></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="40" value"<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./footer.html');
?>/code]



it says what is really happening, "Access denied for user 'SYSTEM'@'localhost' (using password: NO)"

the username or password is wrong

 

if you're not sure what to do, just create a new user using the mysql console, or with phpmyadmin and grant it the privileges on this database

it says what is really happening, "Access denied for user 'SYSTEM'@'localhost' (using password: NO)"

the username or password is wrong

 

if you're not sure what to do, just create a new user using the mysql console, or with phpmyadmin and grant it the privileges on this database

 

Hi, I used this in the mysql console:

 

GRANT ALL ON *.* TO 'SYSTEM'@'localhost';    just to make the code happy.  It took the error you helped me with off but now it's saying

 

No database selectedQuery: INSERT INTO users (first_name,last_name, email, password, registration_date) VALUES ('Brenton','Hale', 'RacerJM05@aol.com', SHA('ss'), NOW() )

 

 

 

What do I type to select a database?  the database name is "sitename"  and the only table within is "users".  That's where I have been instructed to place all of this data in.  The reason I''m asking you and on here is because I don't want to message my code up since its ERROR FREE now.

 

Thanks!

 

 

Ok, why are you using SYSTEM for a username? That is just weird, in my opinion.

 

To solve the issue you have to select the database you want to use by using mysql_select_db or else it will not know where to pull the data from. You will want to call this right after the mysql_connect statement.

Thank you so very much!  I changed the SYSTEM to = username  since I do admit it was a little weird like you said.  Not that username is much better. lol

 

But, anyways... it posted to the database and I got this message confirming it.

 

Connected successfullyThank you!You are now registered.  In Chapter 9 you will actually be able to log in!

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.