0

Can anyone explain what the $PHP_SELF global variable does in the following script?

<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
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 {
echo "Sorry, no records were found!";
}
?>
</body>
</html>

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by holy-food
0

PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder).

0

Let's say the code you posted above is on a file named 'test.php' and that the URL to that file (which you are currently executing) is http://yoursite.com/somefolder/test.php $PHP_SELF then equals "/somefolder/test.php".

In your printf() function you have: <a href="%s"...> that first %s is replaced with the value of $PHP_SELF

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.