Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

This is where I think it´s the problem...

$sql1 = "SELECT `puntos_globales`, '$juego' 
         FROM `lista_jugadores` WHERE `id_jugador`='$noTop'";

This is the error message:

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 "blackOps2'='1' WHERE `id_jugador` = '10" at line 1

$juego .. is a php variable that holds the column name; in this case blackOps2. I don´t know why in the error says blackOps2'='1'??

share|improve this question

marked as duplicate by mario, Andy Lester, Michael Irigoyen, Vitus, Patrick Evans Aug 23 '13 at 19:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
the error is not same as your query , please provide your true query –  echo_Me Aug 23 '13 at 15:45
2  
' turns things into a strings and removes any "significance" they might have to the database. foo would be a field/table name, 'foo' is just a string that contains the word foo. –  Marc B Aug 23 '13 at 15:45
1  
You did use backticks for one column name but apostrophes for another. What was your reason? –  Your Common Sense Aug 23 '13 at 15:46
    
Never use backticks around column names. They are just one more way for you to make syntax errors. The only reason you need them is if you have a column name that is a reserved word, and using column names that are reserved words is a terrible idea as well, so that's two bad habits you can avoid at once. –  Andy Lester Aug 23 '13 at 15:53
    
You are leaving yourself wide open to SQL injection attacks. Please learn about using parametrized queries, preferably with the PDO module, to protect your web app. bobby-tables.com/php has examples to get you started. –  Andy Lester Aug 23 '13 at 15:53

1 Answer 1

from the error it seems you didnt provide the true query and it looks you have two where clause

     blackOps2='1' WHERE `id_jugador` = '10"

try do it like that

     WHERE `id_jugador` = '10' AND blackOps2='1'
share|improve this answer
    
blackOps2 is a column name that $juego holds...I don´t know why the error says that... –  Xavier Odin Soto Aug 23 '13 at 16:05
    
even what you said but its not the same query in the error message. where you have ='1' ? and before WHERE you have table name not $juego. either you providing wrong query or you the query is colled with something else. –  echo_Me Aug 23 '13 at 16:07
    
thanks to you I could find the problem. The problem was in the next line: $sql2 = "UPDATE lista_jugadores SET puntos_globales='$ptsG', '$juego'='$ptsJ' WHERE id_jugador='$noTop'; "; The apostrophes around $juego was the problem... Thanks, I am a novice in this... –  Xavier Odin Soto Aug 23 '13 at 16:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.