TNS Posted December 4, 2005 Share Posted December 4, 2005 I don't know if this is a PHP question, or a MySQL question, so please move this if it's in the wrong forum. Anyway, here goes: One of my friends wants to have a page that he can go to and assign points to members of his Halo 2 clan. I've started out extremely simple, but I can't use $gamertag or $points variables in some sql queries and I can in others. I haven't gotten to checking for existing tables, so I have been switching back and forth between the two $query lines. Here is my code: <html> <head> <title> </title> </head> <body> <?php print("Gamertag = $gamertag<br>\n"); print("Points = $points<br>\n"); //$query = 'INSERT INTO $gamertag VALUES ($points)'; //$gamertag and $points variables do not work $query = "CREATE TABLE $gamertag (points int(3) NOT NULL default '0') TYPE=MyISAM"; //$gamertag variable works $link = mysql_connect('localhost', 'the-bebo_thetaco', '*********); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br>'; mysql_select_db ("the-bebo_paus"); $result = mysql_query($query); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "<br>\n"; $message .= 'Whole query: ' . $query; die($message); } mysql_close($link); ?> </body> </html> Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/2976-variables-in-queries/ Share on other sites More sharing options...
TNS Posted December 4, 2005 Author Share Posted December 4, 2005 Ok, I was premature in my posting. The problem was that I had used single quotes in some places. I changed my INSERT query to the following code, and it worked perfectly. $query = "INSERT INTO ".$gamertag." VALUES (".$points.")"; Quote Link to comment https://forums.phpfreaks.com/topic/2976-variables-in-queries/#findComment-10006 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.