Page 1 of 1

Mysql Resource ID

Posted: Sun Apr 04, 2004 7:39 pm
by AlbinoJellyfish
I am trying to make a script so you can edit different entries in mysql by the id number. Whenever I use this code, i get a Resource id #2. I have searched this forum, and the posts i read make no sense. I am a N00b at php, so any help would be good.

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?PHP
$id = ($HTTP_GET_VARS[id]);
$db = mysql_connect("localhost", "root");
mysql_select_db("events" , $db)
or die("Couldn't open $db: ".mysql_error());
$query = 'SELECT * FROM events WHERE id="$id"';
$result=mysql_query($query);
echo $result;
?>
</body>
</html>

Posted: Sun Apr 04, 2004 7:46 pm
by AlbinoJellyfish
Notice: Use of undefined constant id - assumed 'id' in /web/admin/test.php on line 11
is an error I get. I have no Idea what this means.
i wanna have it be like
http://www.whatever.com/update.php?id=1

Posted: Sun Apr 04, 2004 7:53 pm
by Illusionist
change:

Code: Select all

$id = ($HTTP_GET_VARS[id]);
to:

Code: Select all

$id = $_GET['id'];
Also you can't jsut echo out the result like that. you can do soemthign like this though:

Code: Select all

<?PHP
$id = $_GET['id'];
$db = mysql_connect("localhost", "root");
mysql_select_db("events" , $db) or die("Couldn't open $db: ".mysql_error());
$query = 'SELECT * FROM events WHERE id="$id"';
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo $row['fieldname'];
echo $row['fieldname'];
//where fieldname is the name of the field int he database.
}
?>
I hope that made more sense!

Posted: Sun Apr 04, 2004 7:59 pm
by AlbinoJellyfish
The only problem is when I echo the $query, it returns

SELECT * FROM events WHERE id="$id"

shouldnt the id number be there?

It doesnt display anything now.

Posted: Sun Apr 04, 2004 8:05 pm
by AlbinoJellyfish
nvm
it was sheer stupidity with quotes
thanks for the help!

Posted: Sun Apr 04, 2004 8:16 pm
by Illusionist
$query = "SELECT * FROM events where id='$id'";