Hi,
I have a problem with some SQL inside a php file. The tricky thing is that the code works just fine locally and I only have the problems when I load it to the host.
The code is used to check if the desired username exists in the database. If it does then the user is informed, at the time of entering the data, using an AJAX process. Part of this process call a php file (datacheck.php) with a query string that contains the item to check. The code that is the problem is this:
[CODE=php]
$lcItemToCheck = $_GET['tocheck']
$lcCheckSQL =
"SELECT COUNT(*) AS test
FROM credential
WHERE userName = $lcItemToCheck" ;
/* I have tried adding '' around the variable, I have tried ending the SQL at =" and adding the variable to it, both with and without ''.
The query ... userName = '" . $lcItemToCheck ."'"; seems to check the database for 'nathj07' which isn't there, I need to check for nathj07.
$result = mysql_query($lc CheckSQL);
[/CODE]
When the SQL is executed it returns the following error:
nathj07 is what was entered in the form. This item is the database, I added it for testing purposes and when I run this locally it works a treat.
Does anyone have any suggestions on what is causing the problem or how to fix it?
Many thanks
nathj
I have a problem with some SQL inside a php file. The tricky thing is that the code works just fine locally and I only have the problems when I load it to the host.
The code is used to check if the desired username exists in the database. If it does then the user is informed, at the time of entering the data, using an AJAX process. Part of this process call a php file (datacheck.php) with a query string that contains the item to check. The code that is the problem is this:
[CODE=php]
$lcItemToCheck = $_GET['tocheck']
$lcCheckSQL =
"SELECT COUNT(*) AS test
FROM credential
WHERE userName = $lcItemToCheck" ;
/* I have tried adding '' around the variable, I have tried ending the SQL at =" and adding the variable to it, both with and without ''.
The query ... userName = '" . $lcItemToCheck ."'"; seems to check the database for 'nathj07' which isn't there, I need to check for nathj07.
$result = mysql_query($lc CheckSQL);
[/CODE]
When the SQL is executed it returns the following error:
Code:
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 '\'nathj07\'' at line 3
Does anyone have any suggestions on what is causing the problem or how to fix it?
Many thanks
nathj
Comment