No data posted through a form to a php page will go into a db unless you code it so. Therefore you can answer your own question simply by writing your validation and db update code in the right order.
A simple example would be as follows:
I am assuming:
- mysql as the db
- the form has one field which must be numeric and is mandatory
- the field name on the form is called 'number'
- the value needs to go into a table called 'Guess'
- table 'Guess' has two fields id (integer autoincrement) and guess (varchar)
// the value of field number is available in var $number
// so validate it - it must be numberic
if (empty($number)) {
// number field has no value
echo "error - number required";
} else {
// number field has a value now check it is valid
// it must be numeric (0-9)
$check = ereg("[^ 0-9]+", $number, $trash);
if ($check) {
// character other than 0-9 found
$echo "Error - must be a number
} else {
// only 0-9 found so save data to db
$sql_query = "INSERT INTO guess (id,guess) VALUES (NULL,$number);
$result = mysql_query($sql_query);
}
This is pretty simple code and will need tighening up in line with your own integrety and error strategies.