Hi Olaf,
thank you for the great Form Validation Code. Works great, i only have 1 question.
When i try to send an EMPTY form the Validation kicks in and gives me the Error MSG.
( works correct )
The Form still inserts 1 Empty Record Set into the DB. If i use the
" die " statement, i cannot get back to the form because it dies . Of Course :-))
Any Ideas on how to prevent it from writing an empty set?
Thanks Eddy
Form Validation Methode
(14 posts) Great offers for webmaster, blogger and web developer!-
Posted 2 years ago #
-
hi,
set some boolean and insert only the db record if the boolean is true (if all required fields are filled). Or like this:
if ($example->validation()) { mysql_query("your query"); }don't use "die" if your form is not valid...
Posted 2 years ago # -
Olaf , Thank you for the quick response,
i have tried the "if" Version before. Forgot to mention it.
if ($example->validation()) { mysql_query("$sql, $link"); }But it still inserts an empty Record. I'm afraid i can't follow you on the Boolean?
Not sure what you mean. The way i understand it is, to write something like this:
(empty($name) || empty($message) etc. and all of the entries must be TRUE before it writes the query.
Cheers EddyPosted 2 years ago # -
Eddy, how do you use the validation class?
Posted 2 years ago # -
Olaf,
i used your validation class and fitted it to my needs ( adding more fields etc.)
And it works great on my Test DB. I'm just unable to stop the first entry into the DB when i open this page. i did set the field for email as unique, this way it prevents any further empty records. Put a small code at the end of the form page to see what it was doing.
if (mysql_query($sql)) { print(mysql_affected_rows() . " rows inserted.\n"); } else { print("SQL statement failed.\n"); }i made sure that all the fields are set to " required = "y"
that's it, i thought lolPosted 2 years ago # -
you need to test if the form is submitted first:
if (isset($_POST['Submit'])) { ...Posted 2 years ago # -
it's in your code from the validation_demo.php
<?php include("validation_class.php"); if (isset($_POST['submit'])) { $example = new Validate_fields; $example->check_4html = true; etc etc. all the way down to } else { $error = $example->create_msg(); }it checks all the fields for correct entries. Works great.
Like i said, until you open the page, then by just doing that it writes that ugly empty Record Set. And i have that big ? in front of my face :-))Posted 2 years ago # -
maybe some other code before or after this statement? or inside some included file?
Posted 2 years ago # -
after the above code there is only
$link = mysql_connect("localhost", "", "") or die ("no connection MySQL-Server!"); $sql = mysql_select_db ("database", $link); then the Postings $first = $_POST[first]; $last = $_POST[last];etc.
then the $sql = "INSERT INTO database .... VALUES... etc.
followed by the form.
That's it. I don't want to post the whole form here.Posted 2 years ago # -
do you have the sql statement after/within the html? don't do this. Check my example code structure
Posted 2 years ago #
Reply »
You must log in to post.