Jump to content

Recommended Posts

Hi, thanks for reading.

 

I seem to get this error when I try logging in through a form I made:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' MD5Password='482c811da5d5b4bc6d497ffa98491e38'' at line 1

 

My query is:

 

$Username = $_POST['username'];
$Password = md5($_POST['password']);

$Query = mysql_query("SELECT * FROM Users WHERE Username='$Username', MD5Password='$Password' LIMIT 1") or die(mysql_error());

 

Would anyone have any suggestions? I'm using hosting from a hosting website.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/153861-solved-login-form-error/
Share on other sites

Hey Maq,

 

Thanks for the reply. That did solve the MySQL error, but now, even though the credentials are valid, I'm being redirected to one of my errors.

 

Does anyone have any clue why this login form would not be validating the correct credentials?

 

Argh.

 

<?php

session_start();

include('config.php');

if (isset($_POST['login'])) {

$Username = $_POST['username'];
$Password = md5($_POST['password']);

$Query = mysql_query("SELECT * FROM Users WHERE Username='$Username' AND MD5Password='$Password' LIMIT 1") or die(mysql_error());
$Get = mysql_fetch_array($Query);
$Theusername = $Get['Username'];
$Thepassword = $Get['MD5Password'];

if (mysql_num_rows($Query == 1)) {

$_SESSION['auth'] = 1;
setcookie("laselfaawef", $Theusername, time()+(84600*30));
header("Location: main.php");
die();

}

if ($Username != $Theusername || $Password != $Thepassword) {

$error = "
<div class=error>
Incorrect username and/or password.
</div>";

} elseif (empty($Username) || empty($Password)) {

$error = "
<div class=error>
Incorrect username and/or password.
</div>";

} else {

$error = "
<div class=error>
An unknown error occurred.
</div>";

}

}

?>

I don't think you need to md5 more than once.

 

Double equals means you are comparing the two. One equal means you are assigning.

 

Changes:

 

if ($Username != $Theusername || $Password != $Thepassword)

 

to:

 

if ($Username !== $Theusername || $Password !== $Thepassword)

 

Made some changes.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.