Hey, im trying to make a PHP Login box for a program that i am making for my A Level project
however, im new with PHP so dont really know much about the code :( lol.

this is what i have so far

<html>

<body>

<?php

$username = "Admin";
$password = "Password";

if ($username=!$password; )
{ 
     print "The Username or Password is incorrect";
}

elseif ($username=$password; )
{
    (i want it to go to a webpage if the username and password match)
}

?>

<p align="left"><font face="Arial" size="5"><b>Login</b></font></p>
<table border="0" width="29%" id="table2">
    <tr>
        <td><b><font face="Arial" size="4">Username:</font></b></td>
        <td width="148"><input type="text" name="Username" size="20"></td>
    </tr>
    <tr>
        <td><b><font face="Arial" size="4">Password:</font></b></td>
        <td width="148"><input type="password" name="Password" size="20"></td>
    </tr>
</table>



</body>
</html>

im not sure if this is correct or not.
if there is somebody that can help can you please email me.
[email snipped]
or, post here.

thanks alot

Sean

Recommended Answers

All 2 Replies

Hey Sean,

You need to begin by learning the proper way of writing HTML, then the php syntax, then working on your logic...

Just so you know no one here is going to write code for you, well I guess I can only speak for my self. But I'll get you started on fixing your problems...

1. Your HTML is missing a <form></form> tags, which is essential if you want your information to be submitted somewhere.

2. The user name and password variables will overwrite your actual user name and password submitted from the form since they are named the same. Also look into using $_GET[], $_POST[], $_REQUEST[].

$username = "Admin";
$password = "Password";

3. Following line of code is checking if password is not equal to user name. Why would you check if password is the same as user name, makes not sense and has nothing to do with knowledge of PHP, your logic is missing.

if ($username=!$password; ) ...

Should be something along the lines of ...

if($secretUser==$_POST['username'] && $secretPass==$_POST['password']){
   // let them in...
} else {
  // display error message...
}

4.

elseif ($username=$password; )

First there is not elseif in PHP (that's VB syntax), Second, you must use double == signs when comparing values otherwise you have just assigned the value of $password to the $username.

Get this to work and comeback, there is more then enough references on google regarding what you're doing here. We'll be glad to help you further.

yeah thanks alot.
i have sorted it out now and have fully working login boxes :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.