Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2004
    Posts
    10

    Unanswered: PHP variables and HTML-POST ?

    I'm a newbie to PHP and HTML in general, I'm trying to do a login-page where i use HTML form with POST to grab user and password and send it back to the same page so that I can check it with my MySQL database. PHP variables doesn't seem to hold my user/pass variables.
    I've done some "if's" that should return some error messages to screen if user and password does'nt match.

    When I type user and pass in login.php page it only blibs and doesn't give me any result printed on on screen back to me.
    I've tried breaking out just the the connection to MySQL with static varables in a standalone script and this seems to work fine, but when i use the combined HTML form with POST and PHP it doesn't work.

    Do i have to use the PHP - session_start()/sessio_register function to save the input in my PHP-variables?

    Anyone got an idea what I'm doing wrong here?
    I could post my code here later if that would help (don't have it here right now).

    /Leo

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have you checked the PHP ini file to make the variables vivisble to the code, otherwise I think you have to explicitly define which object you waant to access. I think the ini line is somehting like "global variables", or the alternative is to search on this forum where someone else has had this problem within the last 2.3 weeks

  3. #3
    Join Date
    Aug 2004
    Posts
    10
    ah oki, i'll check that, thanks
    Saw another post here on some problems with firewall (Zone alarm) and windows XP. I'm using winXP and I have Norton internet security as FW, maybe that has some effect on this.

    /Lennart

  4. #4
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    10

    Talking

    you can do it this way
    PHP Code:
    <? //login.php ?>
    <html>
    <body> 
    <form action="login.php" method="post" target="_self">
    Username: <input type="text" name="username"> <br>
    Password: <input type="password" name="password"> <br>
    <input type="submit" value="go!">
    </form>
    <?
    //here you can connect to you DB to fetch your $password and $username
    if ($_POST['username']==$username && $_POST['password']==$password)
    {
     
    //display your page
    ?>

    <h1>Welcome to my HomePage</h1>

    <?
    }else
    {
     if (
    $_POST['username']!=$username) echo "wrong username";
     if (
    $_POST['password']!=$password) echo "wrong password";
     echo 
    "<strong><font color=\"#ff0000\">Access denied ! </font></strong>";
    }
    ?>
    </body>
    </html>
    hope that work, its not testet ;P
    [/.. Höre alles, glaube wenig, sage nichts ..\]

  5. #5
    Join Date
    Aug 2004
    Posts
    10

    Talking

    thanks, this looks very useful :-)

    /Lennart

  6. #6
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    10
    but you should also use the function isset() ... ohterwise the scriptwill always look if username and password fit ... try this:
    PHP Code:
    if (isset($POST_['username']) && isset($_POST['password']))
    {
    if (
    $_POST['username']==$username && $_POST['password']==$password
    [...]

    =)
    [/.. Höre alles, glaube wenig, sage nichts ..\]

Posting Permissions

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