Jump to content
Larry Ullman's Book Forums

jfkirkpatrick

Members
  • Content Count

    7
  • Joined

  • Last visited

Everything posted by jfkirkpatrick

  1. Larry, Persistence wins out!! I was changing the Update function not the Insert function!! date('Y-m-d H:i:s') worked. Now on to the next challenge!! John K
  2. Sorry, I have to ask this but I have not been able to find a solution via Google search for something that should be simple!! My usertype table has a date_created field similar to your customer table and I want to update this field via PHP. I searched the code I downloaded and can not seem to find where you updated this field. Modifying your example, I have created a table, usertype, that has the field modifedDate defined as: 'modifiedDate' timestamp Not Null Default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. In my insert code, I have the following code (in CodeIgniter): $data = array('userType' => $this->input->post('dusertype'), 'modifiedBy => "Admin', 'modifiedDate => date('d-m-Y H:i:s'); $this->db->insert(usertype, $data); The MySQL table fields, usertypeID, userType, modifiedBy are all inserted properly. The data field, modifiedDate, is formatted as 0000-00-00 00:00:00 even if I try Date() or Now(). What am I doing wrong, it seem that it should be so simple?? Thanks. John K
  3. This is not really a New Topic, just a continuation of the same topic. For this test I used the register.php code directly from EX-1 without modification and now I have used your config.inc.php from EX-1. Register.php <?php // This is the registration page for the site. // This file both displays and processes the registration form. // This script is begun in Chapter 4. // Require the configuration before any PHP code as the configuration controls error reporting: require('./includes/config.inc.php'); // The config file also starts the session. // Require the database connection: require(MYSQL); // Include the header file: $page_title = 'Register'; include('./includes/header.html'); // For storing registration errors: $reg_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Check for a first name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['first_name'])) { $fn = escape_data($_POST['first_name'], $dbc); } else { $reg_errors['first_name'] = 'Please enter your first name!'; } // Check for a last name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['last_name'])) { $ln = escape_data($_POST['last_name'], $dbc); } else { $reg_errors['last_name'] = 'Please enter your last name!'; } // Check for a username: if (preg_match('/^[A-Z0-9]{2,45}$/i', $_POST['username'])) { $u = escape_data($_POST['username'], $dbc); } else { $reg_errors['username'] = 'Please enter a desired name using only letters and numbers!'; } // Check for an email address: if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === $_POST['email']) { $e = escape_data($_POST['email'], $dbc); } else { $reg_errors['email'] = 'Please enter a valid email address!'; } // Check for a password and match against the confirmed password: if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,}$/', $_POST['pass1']) ) { if ($_POST['pass1'] === $_POST['pass2']) { $p = $_POST['pass1']; } else { $reg_errors['pass2'] = 'Your password did not match the confirmed password!'; } } else { $reg_errors['pass1'] = 'Please enter a valid password!'; } if (empty($reg_errors)) { // If everything's OK... // Make sure the email address and username are available: $q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'"; $r = mysqli_query($dbc, $q); // Get the number of rows returned: $rows = mysqli_num_rows($r); if ($rows === 0) { // No problems! // Add the user to the database... // Include the password_compat library, if necessary: // include('./includes/lib/password.php'); // Temporary: set expiration to a month! // Change after adding PayPal! // $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )"; // New query, updated in Chapter 6 for PayPal integration: // Sets expiration to yesterday: $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', SUBDATE(NOW(), INTERVAL 1 DAY) )"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) === 1) { // If it ran OK. // Get the user ID: // Store the new user ID in the session: // Added in Chapter 6: $uid = mysqli_insert_id($dbc); // $_SESSION['reg_user_id'] = $uid; // Display a thanks message... // Original message from Chapter 4: // echo '<div class="alert alert-success"><h3>Thanks!</h3><p>Thank you for registering! You may now log in and access the site\'s content.</p></div>'; // Updated message in Chapter 6: echo '<div class="alert alert-success"><h3>Thanks!</h3><p>Thank you for registering! To complete the process, please now click the button below so that you may pay for your site access via PayPal. The cost is $10 (US) per year. <strong>Note: When you complete your payment at PayPal, please click the button to return to this site.</strong></p></div>'; // PayPal link added in Chapter 6: echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="email" value="' . $e . '"> <input type="hidden" name="hosted_button_id" value="8YW8FZDELF296"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> '; // Send a separate email? $body = "Thank you for registering at <whatever site>. Blah. Blah. Blah.\n\n"; mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com'); // Finish the page: include('./includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. trigger_error('You could not be registered due to a system error. We apologize for any inconvenience. We will correct the error ASAP.'); } } else { // The email address or username is not available. if ($rows === 2) { // Both are taken. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; $reg_errors['username'] = 'This username has already been registered. Please try another.'; } else { // One or both may be taken. // Get row: $row = mysqli_fetch_array($r, MYSQLI_NUM); if( ($row[0] === $_POST['email']) && ($row[1] === $_POST['username'])) { // Both match. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; $reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link at left to have your password sent to you.'; } elseif ($row[0] === $_POST['email']) { // Email match. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; } elseif ($row[1] === $_POST['username']) { // Username match. $reg_errors['username'] = 'This username has already been registered. Please try another.'; } } // End of $rows === 2 ELSE. } // End of $rows === 0 IF. } // End of empty($reg_errors) IF. } // End of the main form submission conditional. // Need the form functions script, which defines create_form_input(): // The file may already have been included by the header. require_once('./includes/form_functions.inc.php'); ?><h1>Register</h1> <p>Access to the site's content is available to registered users at a cost of $10.00 (US) per year. Use the form below to begin the registration process. <strong>Note: All fields are required.</strong> After completing this form, you'll be presented with the opportunity to securely pay for your yearly subscription via <a href="http://www.paypal.com">PayPal</a>.</p> <form action="register.php" method="post" accept-charset="utf-8"> <?php create_form_input('first_name', 'text', 'First Name', $reg_errors); create_form_input('last_name', 'text', 'Last Name', $reg_errors); create_form_input('username', 'text', 'Desired Username', $reg_errors); echo '<span class="help-block">Only letters and numbers are allowed.</span>'; create_form_input('email', 'email', 'Email Address', $reg_errors); create_form_input('pass1', 'password', 'Password', $reg_errors); echo '<span class="help-block">Must be at least 6 characters long, with at least one lowercase letter, one uppercase letter, and one number.</span>'; create_form_input('pass2', 'password', 'Confirm Password', $reg_errors); ?> <input type="submit" name="submit_button" value="Next →" id="submit_button" class="btn btn-default" /> </form> <br> <?php // Include the HTML footer: include('./includes/footer.html'); ?> Computer Club of Sun City, AZ RegisterAccess to the site's content is available to registered users at a cost of $10.00 (US) per year. Use the form below to begin the registration process. Note: All fields are required. After completing this form, you'll be presented with the opportunity to securely pay for your yearly subscription via PayPal. An error occurred in script 'C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php' on line 49: array_key_exists() expects parameter 2 to be array, string given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => array_key_exists() expects parameter 2 to be array, string given [2] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [3] => 49 [4] => Array ( [name] => first_name [type] => text [errors] => First Name [values] => Array ( ) [options] => Array ( ) [value] => ) ) ) [1] => Array ( [file] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [line] => 49 [function] => array_key_exists [args] => Array ( [0] => first_name [1] => First Name ) ) [2] => Array ( [file] => C:\wamp\www\ccscFullCalendar\register.php [line] => 163 [function] => create_form_input [args] => Array ( [0] => first_name [1] => text [2] => First Name [3] => Array ( ) ) )) />An error occurred in script 'C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php' on line 49: array_key_exists() expects parameter 2 to be array, string given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => array_key_exists() expects parameter 2 to be array, string given [2] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [3] => 49 [4] => Array ( [name] => last_name [type] => text [errors] => Last Name [values] => Array ( ) [options] => Array ( ) [value] => ) ) ) [1] => Array ( [file] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [line] => 49 [function] => array_key_exists [args] => Array ( [0] => last_name [1] => Last Name ) ) [2] => Array ( [file] => C:\wamp\www\ccscFullCalendar\register.php [line] => 164 [function] => create_form_input [args] => Array ( [0] => last_name [1] => text [2] => Last Name [3] => Array ( ) ) )) />An error occurred in script 'C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php' on line 49: array_key_exists() expects parameter 2 to be array, string given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => array_key_exists() expects parameter 2 to be array, string given [2] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [3] => 49 [4] => Array ( [name] => username [type] => text [errors] => Desired Username [values] => Array ( ) [options] => Array ( ) [value] => ) ) ) [1] => Array ( [file] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [line] => 49 [function] => array_key_exists [args] => Array ( [0] => username [1] => Desired Username ) ) [2] => Array ( [file] => C:\wamp\www\ccscFullCalendar\register.php [line] => 165 [function] => create_form_input [args] => Array ( [0] => username [1] => text [2] => Desired Username [3] => Array ( ) ) )) />Only letters and numbers are allowed.An error occurred in script 'C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php' on line 49: array_key_exists() expects parameter 2 to be array, string given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => array_key_exists() expects parameter 2 to be array, string given [2] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [3] => 49 [4] => Array ( [name] => pass1 [type] => password [errors] => Password [values] => Array ( ) [options] => Array ( ) [value] => ) ) ) [1] => Array ( [file] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [line] => 49 [function] => array_key_exists [args] => Array ( [0] => pass1 [1] => Password ) ) [2] => Array ( [file] => C:\wamp\www\ccscFullCalendar\register.php [line] => 168 [function] => create_form_input [args] => Array ( [0] => pass1 [1] => password [2] => Password [3] => Array ( ) ) )) />Must be at least 6 characters long, with at least one lowercase letter, one uppercase letter, and one number.An error occurred in script 'C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php' on line 49: array_key_exists() expects parameter 2 to be array, string given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => array_key_exists() expects parameter 2 to be array, string given [2] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [3] => 49 [4] => Array ( [name] => pass2 [type] => password [errors] => Confirm Password [values] => Array ( ) [options] => Array ( ) [value] => ) ) ) [1] => Array ( [file] => C:\wamp\www\ccscFullCalendar\includes\form_functions.inc.php [line] => 49 [function] => array_key_exists [args] => Array ( [0] => pass2 [1] => Confirm Password ) ) [2] => Array ( [file] => C:\wamp\www\ccscFullCalendar\register.php [line] => 170 [function] => create_form_input [args] => Array ( [0] => pass2 [1] => password [2] => Confirm Password [3] => Array ( ) ) )) /> © 2014 - Computer Club of Sun City AZ.
  4. It appears that I have a major problems with my installation as programs that use to work no longer do and even phpinfo() fails with a Server Error!! I will research the changes I have made to various Apache and PHP config files otherwise I will remove and re-install everything. John
  5. Greetings, I apoligize for jumping in the middle of this conversation but I too am going crazy trying to get the app started. I am running Win 7 Professional SP1, installed xampp (Version 1.8.0) from ApacheFriends many months ago and have been using it for various other projects so I am comfortable w/ the installation. MySQL v 5.5.25a; Apache 2.4.2; PHP 5.4.4. Apache is running as a service on Port 80 and 443. MySQL is running as a service on Port 3306. Therefore, DOCUMENT_ROOT is c:/xampp/htdocs. The first exercise is in a directory under DOCUMENT_ROOT in a directory called /ecommerce1. config.inc.php and mysql.inc.php are in the includes directory under ecommerce1. So, my question is 2 fold: What exactly does BASE_URI and BASE_URL represent or mean? Looking at the previous question and answer under "Base URL and URI, I am lead to believe that BASE_URI would be 'c:/xampp/htdocs/ecommerce1/' and BASE_URL would be 'localhost/'? Is this a correct assumption? Now the bigger problem!! When trying to execute "http://localhost/ecommerce/index.php" after completing chapter 3 using FireFox, I get severe errors. To remove any of my mistakes, I have substituted the author's code for config.inc.php, mysql.inc.php, index.php, header.php, footer.php & styles.css. config.inc.php has 'BASE_URI', 'c:/xampp/htdocs/ecommerce1/'; 'BASE_URI', 'localhost/', MYSQL, BASE_URI . 'includes/mysql.inc.php' config.inc.php is in the includes directory. Chapter 4 code at the end of this module has been commented out. mysql.inc.php defines have been changed to reflect my DB_USER, PASSWORD parameters. line 42 of the footer.php has been commented out (require ('includes/login_form.inc.php'); Now this is what I am getting when I run localhost/ecommerce1/index.php!! Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at postmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4 Server at localhost Port 80 The Apache Error Log: [Fri Sep 14 04:56:41.851393 2012] [core:error] [pid 2748:tid 1724] [client 127.0.0.1:50235] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Fri Sep 14 04:56:41.851393 2012] [core:error] [pid 2748:tid 1724] [client 127.0.0.1:50235] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Fri Sep 14 05:18:52.937697 2012] [core:error] [pid 2748:tid 1724] [client 127.0.0.1:50661] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Fri Sep 14 05:18:52.937697 2012] [core:error] [pid 2748:tid 1724] [client 127.0.0.1:50661] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Fri Sep 14 14:33:44.195647 2012] [mpm_winnt:notice] [pid 2128:tid 392] AH00422: Parent: Received shutdown signal -- Shutting down the server. [Fri Sep 14 14:33:46.223650 2012] [mpm_winnt:notice] [pid 2748:tid 268] AH00364: Child: All worker threads have exited. [Fri Sep 14 14:40:22.228474 2012] [core:warn] [pid 2796:tid 392] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? [Fri Sep 14 14:40:22.602875 2012] [ssl:warn] [pid 2796:tid 392] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Fri Sep 14 14:40:24.537278 2012] [mpm_winnt:notice] [pid 2796:tid 392] AH00455: Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4 configured -- resuming normal operations [Fri Sep 14 14:40:24.537278 2012] [mpm_winnt:notice] [pid 2796:tid 392] AH00456: Server built: May 13 2012 14:10:15 [Fri Sep 14 14:40:24.537278 2012] [core:notice] [pid 2796:tid 392] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache' [Fri Sep 14 14:40:24.537278 2012] [mpm_winnt:notice] [pid 2796:tid 392] AH00418: Parent: Created child process 2648 [Fri Sep 14 14:40:26.736882 2012] [ssl:warn] [pid 2648:tid 268] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Fri Sep 14 14:40:26.783682 2012] [mpm_winnt:notice] [pid 2648:tid 268] AH00354: Child: Starting 150 worker threads. [Fri Sep 14 19:09:28.865456 2012] [core:error] [pid 2648:tid 1728] [client 127.0.0.1:50528] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Fri Sep 14 19:09:28.870456 2012] [core:error] [pid 2648:tid 1728] [client 127.0.0.1:50528] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. Any suggestions? Thx John
  6. Thank you for your quick reponse. I have several manuals in the mail to bring me up to speed in MySQL and PHP. I will most likely hold off until I have studied these topics more. Thx again John
  7. I am trying to print the employees as a way of verifying my setup including Apache, phpMyAdmin, MySQL, etc. I downloaded the code from the website and reviewed the errata sheet for any errors. I used phpMyAdmin (5.2.17) to set up the database, load the data using the scripts downloaded from the website, etc, so I feel this part of the effort is satisfactory. Set up user and password and changed mysql.inc.php (pg 18) accordingly. The only difference is, because IIS and Wamp Server is on my computer (I will uninstall these products today.). I have been starting phpMyadmin with "http://localhost:8080/phpmyadmin/ because of these other products. I have changed 'config.inc.php' to reflect 'localhost:8080'. So I feel that I have done the setup sucessfully. I use Aptana Studio 3 as my editor and Xampp 1.7.7 to start MySQL 5.1 and phpMyAdmin. When I execute 'dept_form.html' from Aptana using either Firefox or IE8 browers, the initial screen appears, etc. Once I hit 'Submit" the following message appears across the screen: Department Employees "0) { // Get the employees from the database... // Include the database connection script: require_once('mysql.inc.php'); // Query the database: $q = "SELECT * FROM employees WHERE department_id=$did ORDER BY last_name, first_name"; $r = mysql_query($q, $dbc); // Check that some results were returned: if (mysql_num_rows($r) > 0) { // Retrieve the results: while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { echo " {$row['last_name']}, {$row['first_name']} Email: {$row['email']} Phone Extension: {$row['phone_ext']} \n"; } // End of WHILE loop. } else { // No employees. echo ' There are no employees listed for the given department. '; } mysql_close($dbc); } else { // Invalid department ID! echo ' Please select a valid department from the drop-down menu in order to view its employees. '; } ?>" Which is the code from 'dept_results.php' line 11 (approx) after 'if (mysql_num_rows($r) ....". Any suggestions? Thx John
×
×
  • Create New...