*.php?echo=1

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mythix
-


Joined: 13 Jun 2002
Posts: 20
Location: UK - Frome

PostPosted: Fri Jun 14, 2002 8:25 pm    Post subject: *.php?echo=1 Reply with quote

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 View user's profile Send private message Send e-mail Visit poster's website
TheLinker
-


Joined: 05 Apr 2002
Posts: 165
Location: Oslo, Norway

PostPosted: Sat Jun 15, 2002 8:52 am    Post subject: Re: *.php?echo=1 Reply with quote

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 View user's profile Send private message Visit poster's website
mythix
-


Joined: 13 Jun 2002
Posts: 20
Location: UK - Frome

PostPosted: Sat Jun 15, 2002 11:36 am    Post subject: Thanks Reply with quote

Thanks!!!!!

I was using php version 4.2.1

:D
Back to top View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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


Powered by phpBB phpBB Group