Jump to content

Archived

This topic is now archived and is closed to further replies.

TNS

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:

 

<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?

Share this post


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

Share this post


Link to post
Share on other sites

×

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.