$_POST not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joey99881
    New Member
    • Jul 2010
    • 8

    #1

    $_POST not working

    Hi all, please to meet you!

    Im having a problem getting post variables from a form. Here is the form:

    Code:
    <a href='register_form.php'>Not a member?</a>
      <form method='post' action='member.php'>
      <table bgcolor='#cccccc'>
       <tr>
         <td colspan=2>Members log in here:</td>
       <tr>
         <td>Username:</td>
         <td><input type='text' name='username'></td></tr>
       <tr>
         <td>Password:</td>
         <td><input type='password' name='passwd'></td></tr>
       <tr>
         <td colspan=2 align='center'>
         <input type='submit' value='Log in'></td></tr>
       <tr>
         <td colspan=2><a href='forgot_form.php'>Forgot your password?</a></td>
       </tr>
     </table></form>


    Here's the PHP fragment....


    Code:
    <?php
    
    	//include function files for this application
    	require_once('bookmark_fns.php');
    	session_start();
    	
    /*	if (!isset($_POST['username'])) {
      	echo "Uhoh, you need to fill out the whole  form!";
      	exit;
    	} 
    */
    
    	//create short varible names
    	$username = $_POST['username'];
    	$passwd = $_POST['passwd'];
    When I run the script I get....



    Notice: Undefined index: username in C:\wamp\www\Bob s\26\member.php on line 13

    Notice: Undefined index: passwd in C:\wamp\www\Bob s\26\member.php on line 14

    Oddly enough, apart from that the script runs perfectly! What am I doing wrong? Thanks!


    PS On other forums it reccomends surpressing notices. Ive always thought that this is NOT the way forward! :D
    Last edited by Dormilich; Jul 13 '10, 09:06 PM. Reason: Please use [code] tags when posting code
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    if you want to find out what is in a variable, use var_dump()

    In this case do a var_dump($_POST ) and see what's inside it.

    The error just means it doesn't know any items in the post array or 'username' and 'passwd'

    You should fix all errors and notices in your PHP, but suppress them in a production environment.


    Dan

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      PS On other forums it reccomends surpressing notices. Ive always thought that this is NOT the way forward! :D
      this is indeed a recommendation, though not in general, but for productivity servers. for development servers it is a mistake to disable any error level.

      Comment

      • joey99881
        New Member
        • Jul 2010
        • 8

        #4
        thanks for the word-up on the errors question. Used var_dump and discovered that the form works perfectly. It is a separtate link to member.php on another page that was causing the problem. Many thanks again!

        Comment

        Working...