Justin Koivisto wrote:[color=blue]
> Buck Turgidson wrote:[color=green]
>> I am trying to learn PHP. I am confused as to why I need
>> $_SERVER['PHP_SELF'] in the first block, but just $PHP_SELF in the 2nd.
>> I don't see the latter assigned anywhere in the code.[/color][/color]
See my comments below
[color=blue][color=green]
>> elseif ($delete) {
>> // delete a record
>> $sql = "DELETE FROM employees WHERE id=$id";
>> $result = mysql_query($sql);
>> echo "$sql Record deleted!<p>";
>> printf("<a href=\"%s\">Return</a><br>", $_SERVER['PHP_SELF']);
>> }
>> else {
>> // this part happens if we don't press submit
>> if (!$id) {
>> // print the list if there is not editing
>> $result = mysql_query("SELECT * FROM employees",$db);
>> while ($myrow = mysql_fetch_array($result)) {
>> printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF,
>> $myrow["id"], $myrow["first"], $myrow["last"]);
>> printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>",
>> $PHP_SELF, $myrow["id"]);
>> }
>> }[/color]
>
> It's a bug.. both should reference $_SERVER['PHP_SELF'][/color]
A bug .... Where is the bug?
The OP's code or the browser he's using? :-)
The first printf() will print something like
<a href="/script.php">Return</a>
whereas the second will print
<a href="?id=42">First Last</a>
And I think the OP's browser (correctly???) takes the second URL (can
that be called a URL???) as "<current_page>?id=42"
To the OP:
Buck, turn on error reporting for all notices so that you will be
notified when you use variables that do not exit (like $PHP_SELF above).
If you can't change php.ini, insert these two lines at the top of your
scripts:
error_reporting(E_ALL);
ini_set('display_errors', '1');
--
Mail to my "From:" address is readable by all at
http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!