Results 1 to 2 of 2

Thread: php form - fields empty

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    php form - fields empty

    Hello,
    i'm trying to do a check to see if the textboxes on my php form are empty I tried this code

    Code:
    if(isset($_POST['submit']) )  {
        
        if ($name="" && $gotdate="" && $paydate="" && $money="" && $number="" && $info="") {
            
        include('scripts/connect.php');
        
        $name = $_POST['name'];
        $gotdate = $_POST['gotdate'];
        $paydate = $_POST['paydate'];
        $money = $_POST['money'];
        $number = $_POST['number'];
        $info = $_POST['info'];
        
        $sql = "INSERT INTO customers (name, gotdate, paydate, money, number, info)
                    VALUES ('$name','$gotdate','$paydate','$money','$number','$info')";
        $result = mysql_query($sql);
        
        echo "<h3>Thank you, Information Saved!.</h3> $form";
    
    }
    else
        echo "You need to fill in all the fields!<br>. $form ";    
    }
    else
        echo $form;
    Even when I fill in all the fields I still get an error saying You need to fill in all the fields! can anyone help please?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: php form - fields empty

    1) you want to use the equality operator, not the assignment one - it's the difference between = and == ... http://php.net/manual/en/language.op...comparison.php
    2) Your logic doesn't make sense... you're checking to see if all of the variables are empty (actually, in this case you're assigning them all to blank strings) ... and if they are all empty then you set the values and insert them.
    3) Unless you have register globals on, they should be empty by default. But no one should have Register Globals on in the first place.

    this might be some help
    http://croberts.me/2011/12/26/value-...set-and-empty/

    Short answer is that you should be checking your POST fields, not variables that haven't been set yet.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width