PHP IF Statement

Discussion in 'PHP' started by gazza52_2000, Aug 3, 2007.

  1. #1
    Hi all,

    Probably going to be something simple i am doing wrong here so your help is much appreciated.

    I trying to redirect a user to a page when they log in, the if statement used is this.

    if (isset($_POST["username"]))
    {
    if (($_POST["username"]=="myUser") && ($_POST["password"]=="myPassword")) // VALID LOGIN
    {
    $_SESSION["loggedIn"]=true;
    echo "<a href="test.php">Back to Homepage</a>";
    }
    else // INVALID LOGIN
    {
    echo "wrong username and password - click back to try again";
    }
    }
    else // NO USERNAME ENTERED
    {
    echo "username is blank - click back to try again";
    }
    ?>

    The part which is bold and underlined is the problem.

    I keep getting syntax errors, all i want to do is say if login is correct then give them a href link back to the main page.

    The file is called authenticate.php, is it a problem due to the fact it is a .php extention as the HTML part doesnt seem to being recongised.

    Please help.

    Thanks;)
     
    gazza52_2000, Aug 3, 2007 IP
  2. Permoney

    Permoney Active Member

    Messages:
    360
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    70
    #2
    $page = "users/$user.html"; // replace with you page

    header("Location:$page");

    or, you could use a
    echo "<body onload=\"window.location='$page'\">";

    or

    echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=$page\">";

    or of course you could
    include("$page");


    ps I got from here
     
    Permoney, Aug 3, 2007 IP
  3. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Change
    echo "<a href="test.php">Back to Homepage</a>";

    to

    echo "<a href=\"test.php\">Back to Homepage</a>";
     
    LazyD, Aug 3, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    EDIT: Too late...

    
    if (isset($_POST["username"]))
    {
    	if (($_POST["username"]=="myUser") && ($_POST["password"]=="myPassword")) // VALID LOGIN
    	{
    		$_SESSION["loggedIn"]=true;
    		echo "<a href=\"test.php\">Back to Homepage</a>";
    	}
    	else // INVALID LOGIN
    	{
    		echo "wrong username and password - click back to try again";
    	}
    }
    else // NO USERNAME ENTERED
    {
    	echo "username is blank - click back to try again";
    }
    
    
    PHP:
     
    nico_swd, Aug 3, 2007 IP