Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

SQL query failing.

$
0
0
Hello

I have a problem with a SQL query for my web-based game. Could you guys please have a look at it and help me a bit with how to structure this query?

Here is my query code:
//This would be written further up in the code inside a bunch of if-statements
$sign = "X";

// This is the main query part.
$query = $db->prepare("UPDATE game SET `:square`=:sign WHERE player1 = :player1 OR player2 = :player2");
$query->bindParam(":player1", $_SESSION['username']);
$query->bindParam(":player2", $_SESSION['username']);
$query->bindParam(":sign", $sign);
$query->bindParam(":square", $_POST['square']);
                
$query->execute();
$result = $query->fetch( PDO::FETCH_ASSOC );



The $_POST['square'] does here hold the value 13, which is the name of a collum in the database.

Upon executing the code a error is returned.
"Error! SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''13'='X' WHERE player1 = 'Tim' OR player2 = 'Tim'' at line 1"

What am I doing wrong, and how can I change it?

Thank you!
-Tim

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>