Mysql snytax error

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

Mysql snytax error

Postby Taiwo98 » 13. August 2015 15:18

Hello friends. I am running this query but it's not working
<?php
$check = "SELECT * FROM 'users' WHERE username = '$username' && password = '$password'";
$check = mysqli_query($dbconnect, $check) or die (mysqli_error($dbconnect));
$result = mysqli_num_rows($check);
if ($result == 0){
echo "<p><p1>Username not found. Please try again</p></p1>";
} else {
echo "Login successful. You will be redirected in a moment";
header ('location: memberarea.php');
}
?>
It's giving me this error 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 WHERE = username
Taiwo98
 
Posts: 4
Joined: 13. August 2015 14:55
Operating System: Window 8.1

Re: Mysql snytax error

Postby Nobbie » 13. August 2015 17:44

The double && looks very strange and you should use backticks for the column names as well (as you already did for the table name). The problem is, if any of your own names collides with an reserved word, it leads to syntax error. To avoid that, use backticks (especially as you are using very popular names like username and password).
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: Mysql snytax error

Postby Altrea » 13. August 2015 20:02

Your error does not match with the code you showed us.
Either you have executed a query like this:
Code: Select all
SELECT * FROM 'users' WHERE = username [...]

or you have not quoted the correct error message.

We cannot provide proper help with wrong information.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Mysql snytax error

Postby Taiwo98 » 14. August 2015 13:48

Thanks. What I want the query to do is to check if user is found. If found echo login successful and redirect to member area. But It is not working. Please I need more help.
Taiwo98
 
Posts: 4
Joined: 13. August 2015 14:55
Operating System: Window 8.1

Re: Mysql snytax error

Postby Nobbie » 14. August 2015 14:07

Code: Select all
$check = "SELECT * FROM `users` WHERE `username` = '$username'  AND `password` = '$password'";


If you use header("....") function, you CANNOT use echo before, this leads to an error. You must not output anything, when using header() function.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: Mysql snytax error

Postby Taiwo98 » 14. August 2015 14:39

Thanks in advance.... I have corrected the mysql snytax. It's not giving me error again but not fuctioning.
$check = mysqli_query($dbconnect,"SELECT * FROM `users` WHERE `username` = '$username' AND `password_key` = '$password'") or die (mysqli_error($dbconnect));
$result = mysqli_num_rows($check);
if ($result == 0){
echo "<p><p1>Username not found</p></p1>";
} else {
echo "Login successful. You will be redirected in a moment";
Taiwo98
 
Posts: 4
Joined: 13. August 2015 14:55
Operating System: Window 8.1

Re: Mysql snytax error

Postby Nobbie » 14. August 2015 20:20

Taiwo98 wrote:Thanks in advance.... I have corrected the mysql snytax. It's not giving me error again but not fuctioning.


From this point, this is your problem. I cannot debug your application for you.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 11 guests