2DaysAway Posted January 27, 2008 Share Posted January 27, 2008 I'm getting this error: 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 '-_cartelz.ratings WHERE id='8'' at line 1 Here is the query: $query = mysql_query("SELECT total_votes, total_value, used_ips FROM $rating_dbname.$rating_tableName WHERE id='$id_sent' ")or die(" Error: ".mysql_error()); I've checked my config page, the db info is correct and the table info is correct Is the query written correctly? Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/ Share on other sites More sharing options...
revraz Posted January 27, 2008 Share Posted January 27, 2008 Echo $rating_dbname $rating_tableName See what they contain or just echo the $query and see how it looks. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450651 Share on other sites More sharing options...
toplay Posted January 27, 2008 Share Posted January 27, 2008 Check the value of $rating_dbname.$rating_tableName because in the error it looks like there's a dash: -_cartelz.ratings WHERE id='8'' at line 1 Dashes are not allowed in table names (underscores are ok though). Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450652 Share on other sites More sharing options...
2DaysAway Posted January 27, 2008 Author Share Posted January 27, 2008 that dash is in the Database Prefix. I've been using this same database for years now with the dash. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450670 Share on other sites More sharing options...
fenway Posted January 27, 2008 Share Posted January 27, 2008 that dash is in the Database Prefix. I've been using this same database for years now with the dash. Then backticks are in order. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450702 Share on other sites More sharing options...
2DaysAway Posted January 27, 2008 Author Share Posted January 27, 2008 ok, i added backticks: $query=mysql_query("SELECT `total_votes, total_value, used_ips` FROM `$rating_dbname.$rating_tableName` WHERE id='$id' ")or die(" Error: ".mysql_error()); Now I get this error: Error: Incorrect table name 'cartelz_com_-_cartelz.ratings' ratings is the correct table name. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450714 Share on other sites More sharing options...
revraz Posted January 27, 2008 Share Posted January 27, 2008 And your DB name is cartelz_com_-_cartelz ? Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450718 Share on other sites More sharing options...
2DaysAway Posted January 27, 2008 Author Share Posted January 27, 2008 yes, all the info is correct there. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450720 Share on other sites More sharing options...
toplay Posted January 27, 2008 Share Posted January 27, 2008 $query=mysql_query("SELECT `total_votes`, `total_value`, `used_ips` FROM `$rating_dbname`.`$rating_tableName` WHERE `id` = '$id'") or die(" Error: ".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450725 Share on other sites More sharing options...
2DaysAway Posted January 27, 2008 Author Share Posted January 27, 2008 same result. Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450728 Share on other sites More sharing options...
revraz Posted January 27, 2008 Share Posted January 27, 2008 So what changed to make it not work? Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450742 Share on other sites More sharing options...
toplay Posted January 27, 2008 Share Posted January 27, 2008 same result. I updated my previous post. Backtick marks should be around the DB name (and table name). If you get an error again, and I doubt it, always post current code/query and exact error. Thx. See manual: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html Quote Link to comment https://forums.phpfreaks.com/topic/88091-solved-sql-syntax-error/#findComment-450744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.