Jump to content

variables in queries


Recommended Posts

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:


<title> </title>

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;


Any ideas?

Link to comment
Share on other sites

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.")";

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.