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?
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.
it may be an idea to add some error checking to your mysql connection. see the second example here: http://uk.php.net/mysql_connect