Server side validation

I have a text box and a submit button. I want that when the submit button is pressed, the value on the text box will be checked if it matches the values that are on my server before proceeding, and if they don’t match it should give an error report and stop.

All I can make myself is the text box and the submit button, I have tried for hours to find a way to do the rest, but all I can find on the internet are vague explanations and information that a novice like me cannot use. It would be a shame to let me web site that I have worked hard on to go to waste because I cannot do this myself :frowning:

Thank you in advance :wink:

What you are talking about sounds like a “log-in” script. When you enter a user name and password, your form goes to a PHP page that looks the data up in a database and if they match, it continues on to a page. If they do not match, it goes to an error page that says there is a problem. Is that what you are asking for? If so there are thousands of samples for this. It does not have to be a user name and password. This same type of code will work for any input text field. I suggest you google something like this:
“PHP sample log in validation” and you should find a large number of samples to view…

Here is one that explains a lot of the details including a little security. You can look over the code and once you understand how it works, you can alter it to check your own information. Hope it helps…
http://phpeasystep.com/phptu/6.html

There’s a couple of different ways of doing validation, you can do it with ajax/javascript (which can be server-side) and with php. The simplest way is probably php though. A very rough and basic validation would be something like
[php]
if(isset($_POST[‘submit’])) { // submit is the NAME of the button)
if(!empty($_POST[‘textbox’])) { // textbox is the name of your field
$text = mysql_real_escape_string($_POST[‘textbox’]); // necessary if you’re inserting this into a database
} else {
$err = “This box must be filled out!”; // error message
}

if(!$err) {
// do whatever you want if there’s no errors
}
}[/php]

hopefully this helps unconfuse you abit more :slight_smile: Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service