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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP form submit's, $_POST empty

    For the life of me I can't figure out why all fields in $_POST array are unset. When I change method of form to GET it works perfectly, all information is appended to URL. Only POST fails. Any help would be greatly appreciated, frustration is mounting.

    pre_php.php is a db connect script (it works)
    pre_content.php is an html header (it also works).

    Code:
    <?php
    include_once 'includes/pre_php.php';
    $error_message="";
    $clean = array();
    
    if (isset($_POST['signin'])) {
    	$fields = array("username", "password");
    	foreach($fields as $field) {
    		if (isset($_POST[$field]) && !empty($_POST[$field])) {
    			$clean[$field] = trim($_POST[$field]);
    		} else {
    			$error_message.="Please enter your $field<br/>";
    		}
    	}
    	
    	if ($error_message=="") {
    		$sql = "SELECT * FROM accounts WHERE username=? AND password=? LIMIT 1";
    		$st = $pdo->prepare($sql);
    		$values = array($clean["username"], $clean["password"]);
    		$st->execute($values);
    		if (($row=$st->fetch())!==false) {
    			$session = session_start();
    			if ($session) {
    				$_SESSION['username'] = $row["username"];
    				$_SESSION['first_name'] = $row["first_name"];
    				$_SESSION['last_name'] = $row["last_name"];
    				header("Location: index.php");
    			} else {
    				$error_message.="We could not sign you in. Please contact your ****** representative for assistance.<br/>";
    			}			
    		} else {
    			$error_message.="Incorrect email/password combination.<br/>";
    		}
    	}
    } else {
    	$error_message.="WHAT!"; /*this is for debugging, and it executes every time*/
    }
    
    
    include 'includes/pre_content.php';
    ?>
    
    <div align="center">
    <h2>Please sign in below.</h2>
    <h3><?php print $error_message; ?></h3>
    <div id="sign_in_form">
    	<form id="sign_in" name="sign_in" action="sign_in.php" method="post">
    		<div id="sign_in_fields">Username </div><input type="text" name="username"/>
    		<div id="clear"></div>
    		<div id="sign_in_fields">Password </div><input type="password" name="password"/>
    		<div id="clear"></div>
    		<input type="hidden" name="signin" value="signin"/>
    		<input type="submit" value="Sign in"/>
    	</form>
    </div>
    </div>
    Last edited by kareems; 10-30-2009 at 12:36 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    method="get">


    shopuld be "post"
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    method="get">


    shopuld be "post"
    Sorry, that should have been "post". I changed it to test if "get" worked, it still doesn't work wil post.

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    <input type="submit" value="Sign in"/>


    should be


    <input type="submit" value="Sign in" name="signin" />
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    <input type="submit" value="Sign in"/>


    should be


    <input type="submit" value="Sign in" name="signin" />
    Changed it, didn't do the trick.

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    the page above is sign_in.php?
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #7
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    remove this too

    <input type="hidden" name="signin" value="signin" />
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #8
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    put

    print_r($_POST);

    at the top and run it again
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    include_once 'includes/pre_php.php';

    would be

    require_once("includes/pre_php.php");
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #10
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    or include but brackets should be used
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by Phil Jackson View Post
    or include but brackets should be used
    Though not required.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #12
    New Coder
    Join Date
    May 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    remove this too

    <input type="hidden" name="signin" value="signin" />
    Yes, the page above is sign_in.php (when I hit submit it goes to that page, and executes the else statement for the if(isset($_POST['signin']))

    I tried removing the hidden field, that didn't work.

    Also, I use the hidden field to know whether I should execute the script or not. It's useful when I have multiple forms on a page each performing a different action, so I can tell which form has been submitted. It's a method I've used many times in the past.

  • #13
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Quote Originally Posted by Phil Jackson View Post
    or include but brackets should be used
    include, include_once, require & require_once are language constructs not functions. As such the parenthesis are optional.
    John

  • #14
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    thats what the name in your submit button is for. did you add print_r($_POST); at top of the page?
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #15
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    your not altering the post array in include_once 'includes/pre_php.php';
    are you?
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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