By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,829 Members | 2,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,829 IT Pros & Developers. It's quick & easy.

Form Validation

P: 24
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.
Aug 22 '08 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
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']; ?>
Aug 22 '08 #2

P: 24
Thanks for your help. Really appreciate.
Aug 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.