Jump to content
Larry Ullman's Book Forums

Recommended Posts

I got the script working properly, but every time I run it, it puts initial values in email and pass1 boxes. Always the same values (I think. Obviously I cannot see the pass1 value.). If I access from another computer the boxes are clear. Where might it be picking up the information?

  • Upvote 1

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Good question. I think you could argue it either way. I know I'm annoyed when I have to re-enter data upon form resubmission, but extra security is hard to argue against.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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";?>

Share this post


Link to post
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>
          </tr>
          value=<?php if (isset($_POST['first_name'])) echo $_POST ['first_name'];?>

The code should probably be:

<tr>
    <td>
        <input type="text" name="first_name" id="first_name" size="45" value="<?= (isset($_POST['first_name'])) ? $_POST ['first_name'] : ''; ?>"/>
    </td>
</tr>
          

Share this post


Link to post
Share on other sites

lupiya, I mean that you have errors, and one way to debug those errors is to add echo statements throughout your code to output the values of variables, etc., to confirm (or disconfirm) that the values you are setting are set as you are expecting.

Make sense?

Share this post


Link to post
Share on other sites

Oh, I see what you mean... U are right. Antonio also pointed out to me that there are a whole lot of mistakes. I am in the process of debugging - (wish me luck) !

Share this post


Link to post
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.

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

Loading...

×
×
  • Create New...