Completely n00b PHP problem.

Discussion in 'Mac Programming' started by mmmdreg, May 1, 2007.

  1. mmmdreg macrumors 65816

    mmmdreg

    Joined:
    Apr 14, 2002
    Location:
    Sydney, Australia
    #1
    The following is nearly pretty much copied out of a book.. yet the user variable is blank. IE, in the second file, "echo $_Post['user'];" outputs nothing even though I inputted something. Am I doing something wrong?

    George

    Code:
    <?php
    	session_unset();
    ?>
    <html>
    	<head>
    		<title>Please Log In</title>
    	</head>
    	<body>
    		<form method="post" action="page2.php">
    			<p>Enter your username:
    				<input type="text" name="user">
    			</p>
    			<p>
    				<input type="submit" name="Submit" value="Submit">
    			</p>
    	</body>
    </html>
    Code:
    <?php
    	session_start();
    	$_SESSION['username'] = $_Post['user'];
    	$_SESSION['authuser'] = 0;
    	
    	if ($_SESSION['username'] == 'George') {
    		$_SESSION['authuser'] = 1;
    	} else {
    		echo "Sorry, no permission";
    		echo $_Post['user'];
    		exit();
    	}
    ?>
    <html>
    <head>
    <title>Title</title>
    </head>
    <body>
    <?php
    	echo "Welcome";
    ?>
    </body>
    </html>
     
  2. colocolo macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #2
    Two things :

    1.- Close your form on the first page

    2.- post is with capital letters: $_POST["user"] . PHP is case-sensitive. :)
     
  3. mmmdreg thread starter macrumors 65816

    mmmdreg

    Joined:
    Apr 14, 2002
    Location:
    Sydney, Australia
    #3
    Silly me. Thanks dude.

    George
     
  4. LtRammstein macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #4
    Don't forget to post in the PROPER FORUM! PHP is web-based, so it should be in the Web Development forum.

    Just a little FYI. ;)

    Steve
     
  5. slooksterPSV macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
  6. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #6
    I'm fairly certain that you need to call the session_start(); function at the top of the first page in order to use the session array.
     
  7. lorductape macrumors 6502

    lorductape

    Joined:
    Jun 23, 2006
    Location:
    t3h usa
    #7
    l0l n00b

    </sarcasm>

    it's still better than I could do, i can do c++ and TI-83
     

Share This Page