PHP Scripts Development » PHP Classes Support Forum

Form Validation Methode

(14 posts)

Great offers not only for geeks!


  1. User has not uploaded an avatar

    elight
    Member

    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

    Posted 5 months ago #
  2. 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 5 months ago #
  3. User has not uploaded an avatar

    elight
    Member

    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 Eddy

    Posted 5 months ago #
  4. Eddy, how do you use the validation class?

    Posted 5 months ago #
  5. User has not uploaded an avatar

    elight
    Member

    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 lol

    Posted 5 months ago #
  6. you need to test if the form is submitted first:

    if (isset($_POST['Submit'])) {
      ...
    Posted 5 months ago #
  7. User has not uploaded an avatar

    elight
    Member

    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 5 months ago #
  8. maybe some other code before or after this statement? or inside some included file?

    Posted 5 months ago #
  9. User has not uploaded an avatar

    elight
    Member

    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 5 months ago #
  10. do you have the sql statement after/within the html? don't do this. Check my example code structure

    Posted 5 months ago #

RSS feed for this topic

Reply »

You must log in to post.