Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''information' WHERE 'id' = 'SELECT `id` FROM `account` WHERE `username` ='stswil' at line 1
PHP
<?php
include "connection.php";
$username =$_POST['username'];
$password =$_POST['password'];
$query = " SELECT `username`, `password` FROM `account` WHERE `username` = '$username' AND `password` = '$password' ";
$id = "SELECT `id` FROM `account` WHERE `username` ='$username' ";
$IDquery = " SELECT 'id' FROM 'information' WHERE 'id' = '$id' ";
$IDresults = mysqli_query($conn, $IDquery) or die(mysqli_error($conn));
$result="";
$results = mysqli_query($conn, $query) or die(mysqli_error($conn));

if(mysqli_num_rows($results)!=1){
	$result="Non-Vaild user";
}
else if(mysqli_num_rows($IDresults)!=1){
	header( 'Location: https://xesusanproject.000webhostapp.com/information.html' ) ;
}
else{
	header( 'Location: https://xesusanproject.000webhostapp.com/information.php' ) ;
}
?>
<!DOCTYPE html>
	<head>
		<link rel="apple-touch-icon" sizes="180x180" href="images/favicons/apple-touch-icon.png">
		<link rel="icon" type="image/png" href="images/favicons/favicon-32x32.png" sizes="32x32">
		<link rel="icon" type="image/png" href="images/favicons/favicon-16x16.png" sizes="16x16">
		<link rel="manifest" href="manifest.json">
		<link rel="mask-icon" href="images/favicons/safari-pinned-tab.svg" color="#741372">
		<meta name="apple-mobile-web-app-title" content="Medical Database">
		<meta name="application-name" content="Medical Database">
		<meta name="theme-color" content="#741372">
		<link rel="stylesheet" href="style/main.css" type="text/css">
		<title>Sucess-Login</title>
	</head>
	<body>
		<menu>
			<ul>
				<li><a href="logout.php">Log Out</a></li>
			</ul>
		</menu>
		<span style="margin:0px 0px 0px 10px"><?php echo $result ?></span>
	</body>
</html>

Update

New error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'stswilliams15' '' at line 1

from updating
PHP
$IDquery = " SELECT `id` FROM `information` WHERE `id` = '$id' ";

Wanted to get the id from account (The person just logged in with that information). Then find the matching id in the information to see if there data already in information table. If there no matching id in the information table then I want to go to "https://xesusanproject.000webhostapp.com/information.html" to added the data. If there is matching id then I want the data to be shown

What I have tried:

checking vairables, asking for people in real life
Posted
Updated 12-Jan-17 15:43pm
v3
Comments
j snooze 12-Jan-17 17:40pm    
You don't need parenthesis around SELECT `id` FROM `account` WHERE `username` ='$username'? Most SQL I know of needs parenthesis when doing a subquery like that.
Katherynliza 12-Jan-17 18:53pm    
What do you mean?
Mohibur Rashid 12-Jan-17 17:47pm    
Your IDquery statement is wrong, you have mixed up between grave accent(`) and single quote('),
Katherynliza 12-Jan-17 18:53pm    
Thanks, but now is is this error. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'stswilliams15' '' at line 1
Mohibur Rashid 12-Jan-17 19:41pm    
Echo your sql, run that from console and try to understand the result.

1 solution

Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''information' WHERE 'id' = 'SELECT `id` FROM `account` WHERE `username` ='stswil' at line 1

The problem comes from
PHP
$id = "SELECT `id` FROM `account` WHERE `username` ='$username' ";
$IDquery = " SELECT 'id' FROM 'information' WHERE 'id' = '$id' ";

In second line, the $id is replaced by its contain, second line become.
PHP
$IDquery = " SELECT 'id' FROM 'information' WHERE 'id' = 'SELECT `id` FROM `account` WHERE `username` ='$username' ' ";

Need to know what was your intend there to understand what is wrong.
 
Share this answer
 
Comments
Katherynliza 12-Jan-17 21:15pm    
Wanted to get the id from account (The person just logged in with that information). Then find the matching id in the information to see if there data already in information table. If there no matching id in the information table then I want to go to "https://xesusanproject.000webhostapp.com/information.html" to added the data. If there is matching id then I want the data to be shown.
Patrice T 12-Jan-17 21:27pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Katherynliza 12-Jan-17 21:44pm    
Ok, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900