Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Validating Data with a conditional

    Hey guys,

    Pretty brand new to PHP so learning as I go.

    I've got a web form which posts to a file called signup.php. Now within this file i'm trying to take a post variable $_POST[name] and see if its actually empty.

    I have an if loop in place to check BUT no matter what I do it doesnt seem to fire. It def has something to do with the code below it because it works when I remove that code.

    Anyway, any ideas?

    P.S I know its horrible code but im slowly learning bit by bit.

    Code:
    if ( ! empty($_POST['name']))
     	{  
            
        }
    	else
    	{
    	 header('Location:signup.php');
         }
    	 
    	 
    
    // escape user input
    
    $_POST[name] = mysql_real_escape_string($_POST[name]);
    $_POST[email] = mysql_real_escape_string($_POST[email]);
    $_POST[company] = mysql_real_escape_string($_POST[company]);
    $_POST[country] = mysql_real_escape_string($_POST[country]);
    $_POST[password] = mysql_real_escape_string($_POST[password]);
    
    // Encrypt the password using MD5
    
    $_POST[password] = md5($_POST[password]);
    
    // store client ip address to variable
    $ip = $_SERVER['REMOTE_ADDR'];   
    
    // Insert sanitized POST data into the mysql database
    
    $sql="INSERT INTO sellers (name, email, company_name, country, password, ip_address)
    VALUES
    ('$_POST[name]','$_POST[email]','$_POST[company]','$_POST[country]','$_POST[password]','$_POST[ip]')";
    
    if (!mysql_query($sql))
    {
    die('Error: ' . mysql_error());
    }
    
    
    header('Location:signupsuccess.php');

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,400
    Thanks
    11
    Thanked 297 Times in 296 Posts
    At a minimum, you're missing all the quotes in the post array references...
    Code:
    $_POST['name'] = mysql_real_escape_string($_POST['name']);

  • Users who have thanked tracknut for this post:

    jryan54 (12-03-2012)

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for that...okay i've added in the quotes....obviously still no effect upon my IF statement.

    So clearly something still going on.

    Anyone? bueller bueller?

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    PHP Code:
    if (empty($_POST['name'])) {header('Location:signup.php');} 
    Based on what you had in the original post it looks like you want to go to the signup page if the name field on the form is blank.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

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