Jump to content
Larry Ullman's Book Forums

Recommended Posts

  • 3 weeks later...

I had the same issue, but it was with just the pass1 box. I modified the form to put the pass1 value in the email box the second time it loaded, and it was a password that I had previously used.


This did bring up a question regarding sticky forms. Is it a good idea to use sticky forms for the password fields? I would think it would be better off making the user retype the passwords for the two password fields. Might be a small inconvenience, but I believe the extra security would be worth it.

Link to comment
Share on other sites

I had a similar problem but it was with the 'password.php' script of Chapter 9.  Larry's reply pointed me to the saved values and I found that 'root' and 'root' were being saved for the localhost URL (ref. Safari->Preferences->Passwords).  I deleted just that one Preferences item and got the script to work.


However, that raised for me the question of how this particular script's FORM became associated with the remembered values.  When I was first trying to prevent 'root' from being populated as a value in the first (email address) field of password's FORM I tried a couple of things, including giving that input field a name other than 'email'.  Nothing I tried worked, until I physically deleted the item in Preferences.


So, what causes a particular form item to be associated with the saved values, and why was this NOT happening with the relative-same fields in the register script?  


And, also, is there a was to specify that the form NOT populate from those browser-saved values?

Link to comment
Share on other sites

  • 4 weeks later...

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



$page_tile = 'Registration';
include "../includes/header.php";
$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.
// Include the footer and quit the script:
include "../includes/footer.php";
// 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>
          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>
          value=<?php if (isset($_POST['last_name'])) echo $_POST ['last_name'];?>
            <td><input type="text" name="email" id="email" size="60"/></td>
         value=<?php if (isset($_POST['email'])) echo $_POST ['email'];?>
            <td><input type="text" name="username" id="username" size="50"/></td>
        value=<?php if (isset($_POST['username'])) echo $_POST ['username'];?>
            <td><input name="pass1" type="password" id="pass1" size="40"/></td>
           value=<?php if (isset($_POST['pass1'])) echo $_POST ['pass1'];?>
            <td>Repeat Password</td>
            <td><input name="pass2" type="password" id="pass2" size="40"/></td>
           value=<?php if (isset($_POST['pass2'])) echo $_POST ['pass2'];?>
          <input name="Submit" type="button" value="Submit" />
<?php include "../includes/footer.php";?>
Link to comment
Share on other sites

You HTML output is incorrect. Look at this:

<td>First Name</td>
            <td><input type="text" name="first_name" id="first_name" size="45"/></td>
          value=<?php if (isset($_POST['first_name'])) echo $_POST ['first_name'];?>

The code should probably be:

        <input type="text" name="first_name" id="first_name" size="45" value="<?= (isset($_POST['first_name'])) ? $_POST ['first_name'] : ''; ?>"/>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...