Jump to content


Photo

variables in queries


  • Please log in to reply
1 reply to this topic

#1 TNS

TNS
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 December 2005 - 03:33 AM

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?

#2 TNS

TNS
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 December 2005 - 04:46 AM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users