BrentonHale Posted December 27, 2009 Share Posted December 27, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/ Share on other sites More sharing options...
mikesta707 Posted December 27, 2009 Share Posted December 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984618 Share on other sites More sharing options...
BrentonHale Posted December 27, 2009 Author Share Posted December 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984619 Share on other sites More sharing options...
Kalland Posted December 27, 2009 Share Posted December 27, 2009 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984622 Share on other sites More sharing options...
BrentonHale Posted December 28, 2009 Author Share Posted December 28, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984640 Share on other sites More sharing options...
BloodyMind Posted December 28, 2009 Share Posted December 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984643 Share on other sites More sharing options...
BrentonHale Posted December 28, 2009 Author Share Posted December 28, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984652 Share on other sites More sharing options...
premiso Posted December 28, 2009 Share Posted December 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984653 Share on other sites More sharing options...
phpSensei Posted December 28, 2009 Share Posted December 28, 2009 edit: nvm you solved that problem, now select a db. Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984655 Share on other sites More sharing options...
BrentonHale Posted December 28, 2009 Author Share Posted December 28, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/186456-fatal-error-message-require_once/#findComment-984659 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.