View previous topic :: View next topic |
Author |
Message |
mythix -
Joined: 13 Jun 2002 Posts: 20 Location: UK - Frome
|
Posted: Fri Jun 14, 2002 8:25 pm Post subject: *.php?echo=1 |
|
|
hmmm. I just installed the abyss webserver and mysql and php. I found a great tutorial explaining it all. howver it hasnt got a troubleshooting section :evil:.
I was just getting into it and how to use the GET method and the querystring when ut all went wrong. The code is supposed to create a document that shows a list of names taken from an mysql database called mydb and display the names as links where the link = "$PHP_SELF?id=x" where x is the primary key the person/record in question.
when clicked on it should show the data held about that person. howver, it never does this! it just displays the list of people again! I checked it more simply by using
echo($id);
and just got a blank document. Does anyone know why this is????? i'm stumped!
below is a copy of the code i was usin'
thanks :wink:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
// display individual record
if ($id) {
$result = mysql_query("SELECT * FROM employees WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("First name: %s\n<br>", $myrow["first"]);
printf("Last name: %s\n<br>", $myrow["last"]);
printf("Address: %s\n<br>", $myrow["address"]);
printf("Position: %s\n<br>", $myrow["position"]);
} else {
// show employee list
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
do {
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
echo "Sorry, no records were found!";
}
}
?>
</body>
</html> |
|
Back to top |
|
|
TheLinker -
Joined: 05 Apr 2002 Posts: 165 Location: Oslo, Norway
|
Posted: Sat Jun 15, 2002 8:52 am Post subject: Re: *.php?echo=1 |
|
|
What version of PHP are you using ??
If you are using v4.2 or bigger, there has been an important change in how you can collect variables from both forms and URL's.
Try out the following test in collection variables from URL. Create a file called getdemo.php and enter the following code...
Code: | <?php
// This will work
echo $_GET["id"]."<br>";
echo $_GET["name"]."<br>";
// This will not work
// echo $id."<br>";
// echo $name."<br>";
?> |
Test the script with getdemo.php?id=24&name=foobar and see the result.
Regards... 8) |
|
Back to top |
|
|
mythix -
Joined: 13 Jun 2002 Posts: 20 Location: UK - Frome
|
Posted: Sat Jun 15, 2002 11:36 am Post subject: Thanks |
|
|
Thanks!!!!!
I was using php version 4.2.1
:D |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|