Jump to content
Larry Ullman's Book Forums

lupiya

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by lupiya

  1. I have a different problem concerning chapter 9. I am using PHP version 5.4.8. I am trying to create a registration script based on page 279. I  made small adjustments to suit the tables in my database, but it seems not to work. Here is how the form looks like in the bowser. I wonder why it is saying "value= value= value= value= value= value=".   My full script and form is below. Many thanks for your help!

     

    Customer Registration value= value= value= value= value= value= First Name Last Name E-Mail Username Password Repeat Password

     

     

    <?php
    $page_tile = 'Registration';
     
    include "../includes/header.php";
     
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $errors = array();
     
    // Is first name registered?
    if (empty($_POST['first_name'])) {
    $errors[] = 'Please enter your first name.';
    } else {
    $fn = mysqli_real_escape_string($dbc, trim($_POST['first_name']));
    }
     
    // Is last name registered?
    if (empty($_POST['last_name'])) {
    $errors[] = 'Please enter your last name.';
    } else {
    $ln = mysqli_real_escape_string($dbc, trim($_POST['last_name']));
    }
     
    // Has the e-mail been entered?
    if (empty($_POST['email'])) {
    $errors[] = 'You forgot to enter your email address.';
    } else {
    $e = mysqli_real_escape_string($dbc, trim($_POST['email']));
     
    }
     
    // If the password is missing or does not match with confirmed password?
    if (!empty($_POST['pass1'])) {
    if ($_POST['pass1'] != $_POST['pass2']) {
    $errors[] = 'Your password did not match the confirmed password.';
    } else {
    $p = mysqli_real_escape_string($dbc, trim($_POST['pass1']));
    }
    } else {
    $errors[] = 'Please enter your password.';
    }
     
     
    // If the submitted data passed all the conditions:
     
    if (empty($errors)) {
     
    // Connect to the database.
     
    require ('../mysqli_connect.php'); 
     
    // Register the user in the database:
     
    $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'),    NOW() )";
     
    $r = @mysqli_query ($dbc, $q); 
    if ($r) { 
     
    // Print a message:
    echo 'Thank you! You are now registered. Please, log in and view our variety of products.</p>';
     
    // If it did not run OK.
     
    } else { 
     
    echo '<p><strong>You could not be registered due to a system error. We apologise for any inconvenience.</strong></p>'; 
    }
     
    // Close the database connection.
    mysqli_close($dbc); 
     
    // Include the footer and quit the script:
    include "../includes/footer.php";
    exit();
     
    // Report the errors.
    } else { 
     
    echo '<h1>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>';
    }
    ?>
     
    <div id="container" class="box">
      <div id="obsah1" class="content box">
        <div class="in">
          <h2 class="mtop0">Customer Registration</h2>
          <form id="customerregistration" method="post" action="registration.php">
            <table width="80%" border="0" cellspacing="2" cellpadding="2">
              
                <td>First Name</td>
                <td><input type="text" name="first_name" id="first_name" size="45"/></td>
              </tr>
              value=<?php if (isset($_POST['first_name'])) echo $_POST ['first_name'];?>
              
                <td>Last Name</td>
                <td><input type="text" name="last_name" id="last_name" size="45"/></td>
              </tr>
              value=<?php if (isset($_POST['last_name'])) echo $_POST ['last_name'];?>
              
                <td>E-Mail</td>
                <td><input type="text" name="email" id="email" size="60"/></td>
              </tr>
             value=<?php if (isset($_POST['email'])) echo $_POST ['email'];?>
     
              
          <td>Username</td>
                <td><input type="text" name="username" id="username" size="50"/></td>
              </tr>
              
            value=<?php if (isset($_POST['username'])) echo $_POST ['username'];?>
     
              <tr>
                <td>Password</td>
                <td><input name="pass1" type="password" id="pass1" size="40"/></td>
              </tr>
               value=<?php if (isset($_POST['pass1'])) echo $_POST ['pass1'];?>
     
              
                <td>Repeat Password</td>
                <td><input name="pass2" type="password" id="pass2" size="40"/></td>
              </tr>
               value=<?php if (isset($_POST['pass2'])) echo $_POST ['pass2'];?>
     
            </table>
            <p>
              <input name="Submit" type="button" value="Submit" />
            </p>
          </form>
        </div>
      </div>
    </div>
    <?php include "../includes/footer.php";?>
  2. Hi Again!

    I finally got the CSS to work (index.php and calculator.php.) However, when I click from the index page to the calculator, I get an error saying:

    The requested URL /dynamic/includes/calculator.php was not found on this server.

    I have placed the files as described above ie Applications/MAMP/htdocs/dynamic/includes, while the calculator file is in a folder called dynamic. It seems the links in the browser are not connected. How do I get them to be connected to each other ? Hope Larry or someone else sees this. Thank you all...!!

  3. I seem to have a similar problem. The includes seem to work ok, but the styles do not show when I test index.php. I am doing the exercises on pages 79 to 84 exactly as it says in the book. It seems there is something wrong with the styles. I have saved my website files like so:

    Applications/MAMP/htdocs/dynamic/includes. The dynamic folder contains the other webpages from the book, while the includes folder contains footer.html, header.html, index.php and style.css.

    The header.html has css linked to it and I have set variable for the page tile and included the header in the index.php as such:

     

    $page_title = 'Welcome to this Site!';

    include ('includes/header.html');

    It still does not work.

    How can I make the CSS work? Please help! Thanks :)

  4. My problem is a different one, but it's also on the same exercise on retrieving errors. I am connected to the data base and I have done the exercise on pages 282 and 283 , i.e. trying to retrieve the query results, yet I am getting a blank page when I view it in browsers: safari, firefox, chrome, opera (sorry Have no IE). Anyone who has done this exercise and ready to help with a solution?

  5. On page 252 it says when the error reporting is turned off (set to zero), php does not display any errors. But when I tried to do the same, it actually displayed errors. I am using php version 5.5.25. Could something be wrong with my version or is there something I do not know?

    This is what I did:

     

    error_reporting(0);

    //Create errors:

    foreach ($var as $v) {}

    $result = 1/0;

     

    And I got this result:

     

    Testing Error Reporting

     

    Notice: Undefined variable: var in /Applications/MAMP/htdocs/php/report_errors.php on line 16

     

    Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/php/report_errors.php on line 16

     

    Warning: Division by zero in /Applications/MAMP/htdocs/php/report_errors.php on line 17

×
×
  • Create New...