pinacoladaxb Posted November 11, 2009 Share Posted November 11, 2009 I'm having some trouble with a query I'm trying to make. I can't figure out what's wrong here. Can anyone see the issue? sqltest.php source: <?php $q = 'test'; $con = mysql_connect('localhost', 'pauliuko', 'password') or die(mysql_error()); mysql_select_db('pauliuko_atomicriot', $con) or die(mysql_error()); $query = mysql_query("SELECT COUNT(*) FROM 'ac_users' WHERE 'username' = '$q'") or die(mysql_error()); list($number)=mysql_fetch_row($query); echo $number; mysql_close($con); ?> sqltest.php displays: 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 ''ac_users' WHERE 'username' = 'test'' at line 1 I double checked my database and there is a table named 'ac_users' with a column named 'username'. Link to comment https://forums.phpfreaks.com/topic/181060-please-help-sql-syntax-error/ Share on other sites More sharing options...
haku Posted November 11, 2009 Share Posted November 11, 2009 You are using quotes (') and you need to use backticks (`). Link to comment https://forums.phpfreaks.com/topic/181060-please-help-sql-syntax-error/#findComment-955452 Share on other sites More sharing options...
MattR Posted November 11, 2009 Share Posted November 11, 2009 Yeah, try this: $query = mysql_query("SELECT COUNT(*) FROM `ac_users` WHERE `username` = '$q'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/181060-please-help-sql-syntax-error/#findComment-955472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.