Jump to content
Larry Ullman's Book Forums

Recommended Posts

Chapter 18 - registration form.

I am working on chapter 18 registration form when I validate the name with reg exp it does not accept the input value and reset works fine.

 

php code:

// Validate name:

if(preg_match( '/^[A-Z \'.-]{2, 40}$/i' , $trimmed['name'])) {

$p_name = mysqli_real_escape_string($dbc , $trimmed['name'] );

 

} else {

echo '<p class="error"> Please enter your name. </p>';

 

}

 

 

html code:

 

<label for="name" > Name: </label>

<input type="text" id="name" name="name" size="30" maxlength="40"

value="<?php if(isset($trimmed['name'])) echo $trimmed['name'] ; ?>" />

 

 

 

How can I solve this issue?

Link to comment
Share on other sites

In your HTML code, try changing the label for="name" to something other than "name". I cut and pasted your if statement into my register.php script and that worked fine and the $trimmed statement also looks ok....that leaves the HTML.

Link to comment
Share on other sites

On second look..my suggestion is probably wrong. I just found some HTML code that does the same thing with the label for tag. I still think it may be in your html though. Your if statement worked for me with my HTML which matches what is in the book.

Link to comment
Share on other sites

Now I am using the filter_var() to validate name as you can see below.

// Validate name:

if(filter_var( $trimmed['name'], FILTER_SANITIZE_STRING)) {

$p_name = mysqli_real_escape_string($dbc , $trimmed['name'] );

 

} else {

echo '<p class="error"> Please enter your name. </p>';

}

 

Is that right?

Thank you

Link to comment
Share on other sites

 Share

×
×
  • Create New...