I decided to come back to the world of PHP and, just like how I left it, fall for all the basic errors...
I'm trying to create a login script for my website but for some unknown reason this produces an Internal Error (500).
I'm not sure what part in the script causes this so I'm posting the whole script.
(Error 500's are usually caused (with my site anyway) by a missing semicolon or something stupid)
Thanks in advance!
PHP Code:
if (isset($_COOKIE["Username"])){
echo "<did><p><b>Welcome, ".$_SESSION["Username"]."!</b></p></div>";
}else{
if(isset($_POST['Submit'])) {
if(!empty($_POST['Username'])){
if(!empty($_POST['Password'])){
$mysqli = new mysqli([Removed]);
$Username = $mysqli->real_escape_string($_POST['Username']);
$Password = md5($_POST['Password']);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$Result = $mysqli->query("SELECT * FROM `Users` WHERE `Username` = '$Username' && `Password` = '$Password'");
if($Result->num rows === 1){
$Expires = 1000 * 60 * 60 * 24;
setcookie("Username", $Result['Username'], time()+$Expires);
}else{
echo '<div class="LoginError"><p>That Username or Password is wrong!</p></div>';
}
}else{
echo'<div class="LoginError"><p>Please enter your Username and Password!</p></div>';
}
}else{
echo'<div class="LoginError"><p>Please enter your Username and Password!</p></div>';
}
}
echo <<<END
<form id="Login" Method ="post" Action = "http://thefunnyzone.co.uk/index.php" accept-charset='UTF-8'>
<fieldset style="border: none;">
<label style="position: relative;">Username:</label>
<input Type="Text" name="Username" class="text-input" style="position: relative;"/>
<label style="position: relative;">Password:</label>
<input Type="Password" name="Password" class="text-input" style="position: relative;"/>
<input Type="Submit" Name="Submit" Value="Login" style="position: relative;"/>
</fieldset>
</form>
END;
}
First thing I see is that you left out an underscore on this line:
Code:
if($Result->num_rows === 1){
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
Thank you, that was the main issue!
It appears that the very first if statement causes an issue, though. Please click here and enter User as the username and Password as the Password to see what I mean.
Thanks again!
if (isset($_COOKIE["Username"])){ echo "<did><p><b>Welcome, ".$_SESSION["Username"]."!</b></p></div>"; }else{
You've mixed checking a cookie and checking the session.
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail I'd rather be a comma, then a full stop. User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning
Bookmarks