sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Dhiru1009's Avatar

Form Validation


Question posted by: Dhiru1009 (Newbie) on August 22nd, 2008 02:35 AM
Hi all,

I am new to php and need help. I have two problems.

1. I created a user registration form with three fields username, password and email. I need to implement the validation on these fields using php but I am not sure how to go for that. Any help will be appreciated.

2. My second problem is I am using value="<?=__post('Username');?>" in my form but when I open it in web browser the username field is filled with <?=__post('Username');?> what can I do so that it display blank when open in web browser.

Thanks.
2 Answers Posted
Atli's Avatar
Atli August 22nd, 2008 04:31 AM
Moderator - 2,760 Posts
#2: Re: Form Validation

Hi. Welcome to Bytes!

PHP has many useful functions that help with validation.
htmlspecialchars and htmlentities will strip away HTML tags from the output, making safe to output again.

If you plan on using this in a SQL query, you can use addslashes to make sure quotes and back-slashes will make it through without errors. (Assuming you don't have magic_quotes enabled)
There are also some database specific features you can use, like mysql_real_escape_string for MySQL databases.

For a more specific validation, like say to validate email addresses, you would be best of using regular expressions, using PHPs preg_match or ereg functions.

As to your second problem.
<?=__post('Username');?> is not valid PHP.
The shorthand syntax (<? ?> or <?= ?>) is no longer enabled by default in PHP. You would have to enable it in your php.ini configuration file to use it.

It's always better to use the normal syntax (<?php ?>).
Or in your case: <?php echo $_POST['Username']; ?>
Dhiru1009's Avatar
Dhiru1009 August 22nd, 2008 05:07 AM
Newbie - 22 Posts
#3: Re: Form Validation

Thanks for your help. Really appreciate.
Reply
Not the answer you were looking for? Post your question . . .
197,047 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,047 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top PHP Contributors