#!/usr/bin/php

<?php 
session_start(); 
include("passwords.php"); 
if ($_POST["ac"]=="log") { /// do after login form is submitted  
if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted username and password exist in $USERS array
$_SESSION["logged"]=$_POST["username"]; } else { echo 'Incorrect username/password. Please, try again.'; }; }; if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not
echo "You are logged in."; //// if user is logged show a message
} else { //// if not logged show login form echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> '; echo 'Username: <input type="text" name="username" /><br />'; echo 'Password: <input type="password" name="password" /><br />'; echo '<input type="submit" value="Login" />'; echo '</form>'; }; ?>

i've been trying to get this simple code to work but keep ketting this error..i know its something simple but cant figure it out... Can anyone help?

         if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted
         username and password exist in $USERS array   

    The second line of what I quoted out is what's causing the problem. I assume this should have been on the previous line so as to be part of the comment.

      Finding syntax errors is very very basic stuff. The error message tells you which line the problem is on -- try to use an editor that shows you line numbers and this will make your life easier. There are all kinds of good free ones out there.

      Eclipse PDT, for instance, puts a little red X next to each error it finds.

        10 days later

        Surely this is wrong:

        if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted 
             username and password exist in $USERS array  

        If you have a $USERS array that stores the username then it should be that posted plus put your post data in single quotes and also I think your username and password exist..... is a comment, so it should be:

        if ($_POST['USERS']['username']==$_POST['password']) { /// check if submitted 
            // username and password exist in $USERS array  

        Or even more simply (as I am not sure why you are storing username in an array:

        if ($_POST['username'] == $_POST['password']) { 
          simplypixie wrote:

          If you have a $USERS array that stores the username then it should be that posted plus put your post data in single quotes and also I think your username and password exist..... is a comment, so it should be:

          My guess is that $USERS is an array containing all users and their passwords, indexed by username. So

          if ($_POST['USERS']['username']==$_POST['password']) { /// check if submitted
              // username and password exist in $USERS array 

          I don't think it's part of the form submission. What's more:

          if ($_POST['username'] == $_POST['password'])

          checks to see if someone's username is the same as their password which doesn't sound like a sensible thing to check.

            if ($_POST['USERS']['username']==$_POST['password']) { /// check if submitted 
                // username and password exist in $USERS array 

            Yes, exactly as I put in my reply.

            if ($_POST['username'] == $_POST['password']) 

            Agree, but am only tidying up the code that was originally posted, mine is not to question why 🙂

              simplypixie wrote:

              Yes, exactly as I put in my reply.

              Yes, I was quoting your reply (hence the quote box around it). I was pointing out that your reply didn't make sense. What makes you think that $USERS and $_POST['USERS'] are the same thing?

                What I was saying to the poster is that why they had didn't make sense - they can't just have $USERS as (from the code supplied) there is no information to populate it. It either needs to be a POST or SESSION variable (I don't know the rest of their code which is why I used the $_POST as an example).

                  simplypixie wrote:

                  It either needs to be a POST or SESSION variable

                  ...Or defined in "passwords.php".

                    Amazing - I joined this forum over the weekend to try and help people as I would have liked when I started out and think I will leave it if there are people like you on here.

                    It is all well and good you criticizing my responses (the best responses I can give based on the original information supplied by the poster) but what about actually posting something useful, like the answer to the poster's problem.

                      simplypixie wrote:

                      but what about actually posting something useful, like the answer to the poster's problem.

                      That had already been given by Derokorian within quarter of an hour of the original post. The lack of a reply from the OP after such a quick response suggests it was the right one (though saying so would have been nice).

                      Even you agreed that what you wrote didn't make sense - didn't it occur to you that it might have been because you had misinterpreted what was going on?

                      This is why I usually stay out of the Newbies' forum.

                        Write a Reply...