PHP Mysql problem

Soldato
Joined
6 Jan 2005
Posts
3,633
Location
Cambridge
Hi, I'm having problems with PHP and Mysql

PHP:
$dbname = "***";
$dbpassword = "***";
$dbserver = "localhost";
$db = "***";
mysql_connect($dbserver,$dbname,$dbpassword);
mysql_select_db($db);
$query = mysql_query("SELECT * FROM `$t` WHERE `id`='$id'");
while($output = mysql_fetch_array($query)) {
**do stuff
}

I get this message

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in *** on line 95

I've used mysql_fetch_array() before and its worked

Does anyone know the problem?

Thanks
 
What is stored in the variables $t and $id? Do the name of the table in $t actually exist?

Code:
$query = mysql_query("SELECT * FROM `$t` WHERE `id`='$id'");

To display the message returned by the MySQL Server, change the line to:

Code:
$query = mysql_query("SELECT * FROM `$t` WHERE `id`='$id'") or die(mysql_error());
 
yeah $t and $id are variables, can i use variables with this?

edit: read it wrong sorry, on the link it is URL/page.php?t=php?id=1

maybe this is wrong?
 
Last edited:
edit: read it wrong sorry, on the link it is URL/page.php?t=php?id=1

You need to use $_GET['t'] and $_GET['id'] in this case. Also you really need to look into validating and/or cleaning the data entered by the user. Also consider whether it would be more sensible to hard code the table name.
 
Last edited:
Back
Top Bottom