Jump to content

BrentonHale

Members
  • Posts

    51
  • Joined

  • Last visited

    Never

Everything posted by BrentonHale

  1. mysql> CREATE TABLE order_contents ( -> oc_id INT(10) UNSIGNED NOT NULL -> AUTO_INCREMENT, -> order_id INT(10) UNSIGNED NOT NULL, -> print_id INT(4) UNSIGNED NOT NULL, -> quantity TINYINT UNSIGNED NOT NULL, -> DEFAULT 1, -> price decimal(6,2) NOT NULL, -> ship_date DATETIME default NULL, -> PRIMARY KEY (oc_id), -> KEY order_id (order_id), -> KEY print_id (print_id), -> KEY ship_date (ship_date) -> ) ENGINE=InnoDB; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFA LT 1, price decimal(6,2) NOT NULL, ship_date DATETIME default NULL, PRIMARY' at line 7 mysql> What does all of these errors mean? I'm using the following MySQL Version 5.1.36 . The code looks correct unless the syntax has changed since version 4.1 . If it has, can someone give me the updated code to use.
  2. Is there not a test database in this version, like their was in MySql 4.1 ? Is it the information_schema database or what?
  3. Thank you very much, I believe I'm getting somewhere now with this issue. I have updated apache, mysql, php all with the latest versions. Only problem I'm having now is with the latest release of mysql is this: Could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES) And when I revert back to the previous version of mysql I get this: Error! The email address and password do not match those on file. I'm just going to use the previous version of MySQL. It allowed me to update the password. Everything is working okay now. I have asked so many people for help in various forums, but it was only you who had the correct answer. Thank you!
  4. Windows Vista Home Premium .. im gonna check of all your suggestions and see what happens.
  5. I restarted them a few times, but with no luck. Here is the Apache Error Log for just today only. Right at the time of the apache crash and connection was reset in browser. [sat Jan 02 15:05:49 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 15:05:49 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 15:05:49 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 15:05:49 2010] [notice] Parent: Created child process 8460 [sat Jan 02 15:05:50 2010] [notice] Child 8460: Child process is running [sat Jan 02 15:05:50 2010] [notice] Child 8460: Acquired the start mutex. [sat Jan 02 15:05:50 2010] [notice] Child 8460: Starting 64 worker threads. [sat Jan 02 15:05:50 2010] [notice] Child 8460: Starting thread to listen on port 80. [sat Jan 02 15:05:54 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 15:05:54 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 15:05:54 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 15:05:54 2010] [notice] Parent: Created child process 5136 [sat Jan 02 15:05:54 2010] [notice] Child 5136: Child process is running [sat Jan 02 15:05:54 2010] [notice] Child 5136: Acquired the start mutex. [sat Jan 02 15:05:54 2010] [notice] Child 5136: Starting 64 worker threads. [sat Jan 02 15:05:54 2010] [notice] Child 5136: Starting thread to listen on port 80. [sat Jan 02 15:21:07 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 15:21:07 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 15:21:07 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 15:21:07 2010] [notice] Parent: Created child process 9144 [sat Jan 02 15:21:07 2010] [notice] Child 9144: Child process is running [sat Jan 02 15:21:07 2010] [notice] Child 9144: Acquired the start mutex. [sat Jan 02 15:21:07 2010] [notice] Child 9144: Starting 64 worker threads. [sat Jan 02 15:21:07 2010] [notice] Child 9144: Starting thread to listen on port 80. [sat Jan 02 17:29:11 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 17:29:11 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 17:29:11 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 17:29:11 2010] [notice] Parent: Created child process 6980 [sat Jan 02 17:29:12 2010] [notice] Child 6980: Child process is running [sat Jan 02 17:29:12 2010] [notice] Child 6980: Acquired the start mutex. [sat Jan 02 17:29:12 2010] [notice] Child 6980: Starting 64 worker threads. [sat Jan 02 17:29:12 2010] [notice] Child 6980: Starting thread to listen on port 80. [sat Jan 02 19:55:01 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 19:55:01 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 19:55:01 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 19:55:01 2010] [notice] Parent: Created child process 9152 [sat Jan 02 19:55:02 2010] [notice] Child 9152: Child process is running [sat Jan 02 19:55:02 2010] [notice] Child 9152: Acquired the start mutex. [sat Jan 02 19:55:02 2010] [notice] Child 9152: Starting 64 worker threads. [sat Jan 02 19:55:02 2010] [notice] Child 9152: Starting thread to listen on port 80. [sat Jan 02 21:00:30 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:00:30 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:00:30 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:00:30 2010] [notice] Parent: Created child process 9336 [sat Jan 02 21:00:30 2010] [notice] Child 9336: Child process is running [sat Jan 02 21:00:30 2010] [notice] Child 9336: Acquired the start mutex. [sat Jan 02 21:00:30 2010] [notice] Child 9336: Starting 64 worker threads. [sat Jan 02 21:00:30 2010] [notice] Child 9336: Starting thread to listen on port 80. [sat Jan 02 21:00:34 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:00:34 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:00:34 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:00:34 2010] [notice] Parent: Created child process 9264 [sat Jan 02 21:00:35 2010] [notice] Child 9264: Child process is running [sat Jan 02 21:00:35 2010] [notice] Child 9264: Acquired the start mutex. [sat Jan 02 21:00:35 2010] [notice] Child 9264: Starting 64 worker threads. [sat Jan 02 21:00:35 2010] [notice] Child 9264: Starting thread to listen on port 80. [sat Jan 02 21:01:49 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:01:49 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:01:49 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:01:49 2010] [notice] Parent: Created child process 7696 [sat Jan 02 21:01:50 2010] [notice] Child 7696: Child process is running [sat Jan 02 21:01:50 2010] [notice] Child 7696: Acquired the start mutex. [sat Jan 02 21:01:50 2010] [notice] Child 7696: Starting 64 worker threads. [sat Jan 02 21:01:50 2010] [notice] Child 7696: Starting thread to listen on port 80. [sat Jan 02 21:01:59 2010] [notice] Parent: Received shutdown signal -- Shutting down the server. [sat Jan 02 21:01:59 2010] [notice] Child 7696: Exit event signaled. Child process is ending. [sat Jan 02 21:02:00 2010] [notice] Child 7696: Released the start mutex [sat Jan 02 21:02:01 2010] [notice] Child 7696: All worker threads have exited. [sat Jan 02 21:02:01 2010] [notice] Child 7696: Child process is exiting [sat Jan 02 21:02:01 2010] [notice] Parent: Child process exited successfully. [sat Jan 02 21:02:13 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:02:13 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:02:13 2010] [notice] Parent: Created child process 2716 [sat Jan 02 21:02:13 2010] [notice] Child 2716: Child process is running [sat Jan 02 21:02:13 2010] [notice] Child 2716: Acquired the start mutex. [sat Jan 02 21:02:13 2010] [notice] Child 2716: Starting 64 worker threads. [sat Jan 02 21:02:13 2010] [notice] Child 2716: Starting thread to listen on port 80. [sat Jan 02 21:02:30 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:02:30 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:02:30 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:02:30 2010] [notice] Parent: Created child process 8108 [sat Jan 02 21:02:30 2010] [notice] Child 8108: Child process is running [sat Jan 02 21:02:30 2010] [notice] Child 8108: Acquired the start mutex. [sat Jan 02 21:02:30 2010] [notice] Child 8108: Starting 64 worker threads. [sat Jan 02 21:02:30 2010] [notice] Child 8108: Starting thread to listen on port 80. [sat Jan 02 21:07:38 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:07:39 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:07:39 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:07:39 2010] [notice] Parent: Created child process 9980 [sat Jan 02 21:07:39 2010] [notice] Child 9980: Child process is running [sat Jan 02 21:07:39 2010] [notice] Child 9980: Acquired the start mutex. [sat Jan 02 21:07:39 2010] [notice] Child 9980: Starting 64 worker threads. [sat Jan 02 21:07:39 2010] [notice] Child 9980: Starting thread to listen on port 80. [sat Jan 02 21:08:17 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:08:18 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:08:18 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:08:18 2010] [notice] Parent: Created child process 9928 [sat Jan 02 21:08:18 2010] [notice] Child 9928: Child process is running [sat Jan 02 21:08:18 2010] [notice] Child 9928: Acquired the start mutex. [sat Jan 02 21:08:18 2010] [notice] Child 9928: Starting 64 worker threads. [sat Jan 02 21:08:18 2010] [notice] Child 9928: Starting thread to listen on port 80. [sat Jan 02 21:14:21 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:14:21 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:14:21 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:14:21 2010] [notice] Parent: Created child process 9660 [sat Jan 02 21:14:21 2010] [notice] Child 9660: Child process is running [sat Jan 02 21:14:21 2010] [notice] Child 9660: Acquired the start mutex. [sat Jan 02 21:14:21 2010] [notice] Child 9660: Starting 64 worker threads. [sat Jan 02 21:14:21 2010] [notice] Child 9660: Starting thread to listen on port 80. [sat Jan 02 21:24:53 2010] [notice] Parent: child process exited with status 255 -- Restarting. PHP Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0 [sat Jan 02 21:24:53 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:24:53 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:24:53 2010] [notice] Parent: Created child process 7640 PHP Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0 [sat Jan 02 21:24:53 2010] [notice] Child 7640: Child process is running [sat Jan 02 21:24:53 2010] [notice] Child 7640: Acquired the start mutex. [sat Jan 02 21:24:53 2010] [notice] Child 7640: Starting 64 worker threads. [sat Jan 02 21:24:53 2010] [notice] Child 7640: Starting thread to listen on port 80. [sat Jan 02 21:57:39 2010] [notice] Parent: child process exited with status 255 -- Restarting. [sat Jan 02 21:57:39 2010] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations [sat Jan 02 21:57:39 2010] [notice] Server built: Dec 10 2008 00:10:06 [sat Jan 02 21:57:40 2010] [notice] Parent: Created child process 9700 [sat Jan 02 21:57:40 2010] [notice] Child 9700: Child process is running [sat Jan 02 21:57:40 2010] [notice] Child 9700: Acquired the start mutex. [sat Jan 02 21:57:40 2010] [notice] Child 9700: Starting 64 worker threads. [sat Jan 02 21:57:40 2010] [notice] Child 9700: Starting thread to listen on port 80. Does anyone see anything out of the normal? To be honest I don't have a clue to as what I'm doing. I've only been coding for two weeks and PHP is my first language.
  6. Do you mean? ; Maximum size of POST data that PHP will accept. ; http://php.net/post-max-size post_max_size = 8M If so, what should post_max_size = ? I've tried 8,16,32 and 128... still having the same issue.
  7. Do you mean? ; Maximum size of POST data that PHP will accept. ; http://php.net/post-max-size post_max_size = 8M If so, what should post_max_size = ?
  8. Okay, I found it. What do I need to check and edit? Thank you so much for your replies and all the help!
  9. create a script <?php phpinfo(); ?> open that in the browser and look for Loaded Configuration File on the right of that it will give you the full path to the php.ini file used Okay, here is what I found out per your suggestion. C:\wamp\bin\apache\Apache2.2.11\bin\php.ini I went to that folder and there is (no) php.ini in it. The only file in there is: php5ts.dll Is it possible it could have been deleted? If so, what do I do now?
  10. I can't even find a php.ini file on my pc. I have a php.ini-development and php.ini-production
  11. I'm working on my own machine. I dont have web hosting.. just localhost.
  12. Hi, I'm receiving the following errors when I submit my change password form. I've even downloaded the Scripts from the books site I'm reading and I keep receiving this error: The connection was reset The connection to the server was reset while the page was loading. * The site could be temporarily unavailable or too busy. Try again in a few moments. * If you are unable to load any pages, check your computer's network connection. * If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web. AND also, Apache HTTP Server stopped working and was closed. A problem caused the application to stop working correctly. Windows will notify you if a solution is available. Can someone please reply back with the correct code to use for the password page? Or at least reply back with the line numbers as to where I should add and/or delete the new correct code. Apache 2.2.11 PHP 5.3.0 MySQL 5.1.36 Code editor is Notepad ++ version 5.6.1 Firefox 3.5.6 password.php page <?php # Script 7.8 - password.php // This page lets a user change their password. // Set the page title and include the HTML header. $page_title = 'Change Your Password'; include ('header.html'); // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } // Check for an existing password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your existing password.'; } else { $p = escape_data($_POST['password']); } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your new password did not match the confirmed new password.'; } else { $np = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your new password.'; } if (empty($errors)) { // If everything's OK. // Check that they've entered the right email address/password combination. $query = "SELECT user_id FROM users WHERE (email='$e' AND password=SHA('$p') )"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num == 1) { // Match was made. // Get the user_id. $row = mysql_fetch_array($result, MYSQL_NUM); // Make the UPDATE query. $query = "UPDATE users SET password=SHA('$np') WHERE user_id=$row[0]"; $result = @mysql_query ($query); if (mysql_affected_rows() == 1) { // If it ran OK. // Send an email, if desired. // Print a message. echo '<h1 id="mainhead">Thank you!</h1> <p>Your password has been updated. 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">Your password could not be changed 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(); } } else { // Invalid email address/password combination. echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address and password do not match those on file.</p>'; } } else { // Report the 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. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <h2>Change Your Password</h2> <form action="password.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Current Password: <input type="password" name="password" size="10" maxlength="20" /></p> <p>New Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm New Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Change My Password" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('footer.html'); ?> and mysql.php page <?php # Script 8.1 - mysql_connect.php // This file contains the database access information. // This file also establishes a connection to MySQL and selects the database. // This file also defines the escape_data() function. // Set the database access information as constants. DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); // Select the database. @mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() ); // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // Return the escaped value. return $data; } // End of function. ?> [/code] Can someone please help me out, I've been stuck on this one script for about 5 days now. It's preventing me from moving on with the project/book.
  13. When I remove all of that code above and go to click on "change my password" I receive this message in the browser: The connection was reset The connection to the server was reset while the page was loading * The site could be temporarily unavailable or too busy. Try again in a few moments. * If you are unable to load any pages, check your computer's network connection. * If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web. And when I leave the above code, I get the Parse error: . Either way it's not working.
  14. Hi, I changed the code as you suggested in the mysql_connect.php page. However, i'm still getting this error Parse error: parse error in C:\wamp\www\password.php on line 99 on from the password.php page.
  15. When I removed all of the code for that function (lines 13 - 20): I get connection was reset in the web browser. When I remove only function escape_data ($data) { , I get Parse error: parse error in C:\wamp\www\password.php on line 99 I've checked the code four times now for typo's and can't find any.
  16. When I submit my password.php page to change a user password -- I'm getting this error: Fatal error: Cannot redeclare escape_data() (previously declared in C:\wamp\www\mysql_connect.php:20) in C:\wamp\www\password.php on line 14 I tried deleting at specific line out of the code in both pages, then my connection gets reset. I'm including both page's code. password.php and mysql_connect.php password.php [<?php # Script 7.8 - password.php // This page lets a user change their password. // Set the page title and include the HTML header. $page_title = 'Change Your Password'; include ('./header.html'); // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. // Create function for escaping the data. function escape_data ($data) { global $dbc; // Need the connection. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string (trim($data), $dbc); } // End of function. $errors = array(); // Initialize error array. // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } // Check for an existing password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your existing password.'; } else { $p = escape_data($POST['password']); } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your new password did not match the confirmed new password.'; } else { $np = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your new password.'; } if (empty($errors)) { // If everythings OK. // Check that theyve entereed the right email address/password combination. $query = "SELECT user_id FROM users WHERE (email='$e' AND password=SHA('$p') )"; $result = mysql_query($query); $num = mysql_num_rows($result); if (mysql_num_rows($result) == 1) { // Match was made. // Get the user_id. $row = mysql_fetch_array ($result, MYSQL_NUM); // Make the UPDATE query. $query = "UPDATE users SET password=SHA('$np') WHERE user_id=$row[0]"; $result = @mysql_query ($query); if (mysql_affected_rows() == 1) { // If it ran OK. // Send an email, if desired. // Print a message. echo'<h1 id="mainhead">Thank you!</h1> <p>Your password has been updated. 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">Your password could not be changed due to a system error. We apologize.</p>'; // Public message. echo '<p>' . mysql_error() . '<br/><br/>Query: ' . $query . '</p>'; // Debugging message. include ('./footer.html'); exit(); } } else { // Invalid email address/password combination. echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address and password do not match those on file.</p>'; } } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following errors(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. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <h2>Change Your Password</h2> <form action="password.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Current Password: <input type="password" name="password" size="10" maxlength="20" /></p> <p>New Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm New Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Change My Password" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./footer.html'); ?> and mysql_connect.php <?php # Script 8.1 - mysql_connect.php // This file contains the database access information. // This file also establishes a connection to MySQL and selects the database. // This file also defines the escape_data() function. // Set the database access information as constants. DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); // Select the database. @mysql_select_db (DB_NAME) OR DIE ('Could not select the database: ' . mysql_error()); // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // return the escaped value. return $data; } // End of function. ?>
  17. Thanks, I think I need to get an eye exam. I didn't notice that at all. lol I forgot a $ on line 105 also. Page loads now.
  18. This script is suppose to update database records with PHP code. Its suppose to allow registered users to change their password. I've checked the code twice after typing it up and can't find the mistake. I'm getting an error: Parse error: parse error in C:\wamp\www\password.php on line 45 [<?php # Script 7.8 - password.php // This page lets a user change their password. // Set the page title and include the HTML header. $page_title = 'Change Your Password'; include ('./header.html'); // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. // Create function for escaping the data. function escape_data ($data) { global $dbc; // Need the connection. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string (trim($data), $dbc); } // End of function. $errors = array(); // Initialize error array. // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } // Check for an existing password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your existing password.'; } else { $p = escape_data($POST['password']); } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your new password did not match the confirmed new password.'; } else { $np = escape_data($_POST['password1']); } ] else { $errors[] = 'You forgot to enter your new password.'; } if (empty($errors)) { // If everythings OK. // Check that theyve entereed the right email address/password combination. $query = "SELECT user_id FROM users WHERE (email='$e' AND password=SHA('$p') )"; $result = mysql_query($query); $num = mysql_num_rows($result); if (mysql_num_rows($result) == 1) { // Match was made. // Get the user_id. $row = mysql_fetch_array ($result, MYSQL_NUM); // Make the UPDATE query. $query = "UPDATE users SET password=SHA('$np') WHERE user_id=$row[0]"; $result = @mysql_query ($query); if (mysql_affected_rows() == 1) { // If it ran OK. // Send an email, if desired. // Print a message. echo'<h1 id="mainhead">Thank you!</h1> <p>Your password has been updated. 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">Your password could not be changed due to a system error. We apologize.</p>'; // Public message. echo '<p>' . mysql_error() . '<br/><br/>Query: ' . $query . '</p>'; // Debugging message. include ('./footer.html'); exit(); } } else { // Invalid email address/password combination. echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address and password do not match those on file.</p>'; } } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following errors(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. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <h2>Change Your Password</h2> <form action="password.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset(_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Current Password: <input type="password" name="password" size="10" maxlength="20" /></p> <p>New Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm New Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Change My Password" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./footer.html'); ?>/code] Could someone please point out the mistake, on what line and provide some code to fix it?
  19. Thank you, the problem has been resolved! Thanks for being patient with me, I have less than two weeks experience with PHP coding.
  20. Yes, I used both together. Still not working. I have indented where I seen a " { " . I hope this helps everyone out and makes it easier/faster to see what's wrong with the code. I'm inserting 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. $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('Not connected : ' . mysql_error()); } // Check for previous registration. $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { } else { echo // Already registered. '<h1 id="mainhead">Error!</h1> <p class="error">This email address has already been registered.</p>; } // make sitename the current db $db_selected = mysql_select_db('sitename', $link); if (!$db_selected) { die ('Can\'t use sitename : ' . mysql_error()); } // make sitename the current db $db_selected = mysql_select_db('sitename', $link); if (!$db_selected) { die ('Can\'t use sitename : ' . mysql_error()); } // 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'); ?> Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\register.php on line 75
  21. Hi, I was needing some help with preventing repeat sign ups. I need a query to check the submitted email address ($e) is currently in the database by attempting to select that record. If it's not in the database, then it's safe to register. Here is the existing code (with/out) the prevention of repeated sign ups. Please tell me on which lines (where to add) the code you provide in your replies. <?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. $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('Not connected : ' . mysql_error()); } // make sitename the current db $db_selected = mysql_select_db('sitename', $link); if (!$db_selected) { die ('Can\'t use sitename : ' . mysql_error()); } // make sitename the current db $db_selected = mysql_select_db('sitename', $link); if (!$db_selected) { die ('Can\'t use sitename : ' . mysql_error()); } // 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'); ?> I tried using this code, but the script stopped running. $query = "SELECT user_id FROM users WHERE email='$e'";$result = mysql_query($query);if (mysql_num_rows($result) == 0) { and I tried this code as well: } else {echo '<h1="mainhead">Error!</h1><p class="error">This email address has already been registered.</p>;}
  22. For example, on the first result from database that displays in the browser: first_name:Larrylast_name:Ullmanregistration_date:2009-12-25 19:12:05 It all runs together, I would like to have spaces between the first name, last name, registration date and time. I've tried added simple html, but when I do the page stops displaying anything in the browser. Maybe it i was not coding properly. It would be nice if I could get the results in some sort of table. I need to have Name and Date Registered printed above the columns.
  23. Ever time I play around with the code -- i get an error message and then nothing appears. I've been stuck on this page for three days. At first I was not able to connect to the database, but that HAS BEEN resolved. I just need some help with formatting the results that appear in the browser. Try loading this page in your browser and see what I mean. <?php $page_title = 'View the Current Users'; include ('./header.html'); // Page header. echo '<h1 id="mainhead">Registered Users</h1>'; $username = "username"; $password = "password"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("sitename",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT user_id, first_name, last_name, registration_date FROM users"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "first_name:".$row{'first_name'}."last_name:" .$row{'last_name'}."registration_date:". $row{'registration_date'}."<br>"; //display the results } //close the connection mysql_close($dbhandle); include ('./footer.html'); ?>
  24. I've completely re-written the view_users.php page. I think the problem lies within that page. However, I'm having some formatting issues. It appears that the database is now connecting but the results arn't really readable. Can some help me with this and give me a code sample. <?php $username = "username"; $password = "password"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("sitename",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT user_id, first_name, last_name, registration_date FROM users"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "user_id:".$row{'user_id'}." first_name:".$row{'first_name'}."last_name: ". $row{'last_name'}."registration_date:". $row{'registration_date'}."<br>"; //display the results } //close the connection mysql_close($dbhandle); ?>
×
×
  • 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.