Error 404 when using PHP_SELF

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


Joined: 07 May 2004
Posts: 3

PostPosted: Sat Jul 24, 2004 9:58 pm    Post subject: Error 404 when using PHP_SELF Reply with quote

I am trying out a test script:

Code:

<html>
 <head>
  <title>Learning PHP</title>
 </head>
 <body>

<?php

if($submit){
    // Process Form
    $db = mysql_connect("127.0.0.1", "root", "pcegib");
    mysql_select_db("mydb", $db);
    $sql = "INSERT INTO employees(first,last,address,position) VALUES ('$first','$last','$address','$position')";
    $result = mysql_query($sql);
    echo "Thank you! Information entered.\n";
} else {
    // Display Form
?>

    <form method="post" action="<?php echo $PHP_SELF ?>">
    First Name: <input type="text" name="first"><br>
    Last Name: <input type="text" name="last"><br>
    Address: <input type="text" name="address"><br>
    Position: <input type="text" name="address"><br>
    <input type="submit" name="submit" value="Enter Information">
    </form>

<?php
} // end if
?>

  </body>
</html>



The problem is, when I run the page the first time around, I get this above the form:

Notice: Undefined variable: submit in d:\html\cgi-bin\test\RES\add_entry.php on line 9

And if I fill in the form and submit it, I get an Error 404 (not found) and the URL in the address bar is this:


http://127.0.0.1/cgi-bin/test/RES/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%
3E:%20%20Undefined%20variable:%20%20PHP_SELF%20in%20%3Cb%3Ed:
%5Chtml%5Ccgi-bin%5Ctest%5CRES%5Cadd_entry.php%3C/b%3E%20on%2
0line%20%3Cb%3E20%3C/b%3E%3Cbr%20/%3E


I have the REDIRECT_STATUS set at 200. I had to set it like that or any images shown in a php file (like phpMyAdmin) would automatically launch my Paint Shop Pro program to display each image.

How do I get the above code/form to work? I just upgraded recently to Abyss Web Server X1 (v 1.2.2.2) and this didn't use to be a problem in earlier versions. Earlier versions ran the above script fine, and I had back then set the REDIRECT_STATUS to CGI. Now it has to be set at 200 and my forms don't work. :(

Anyone know of a fix?
Back to top View user's profile Send private message
iNaNimAtE
-


Joined: 05 Nov 2003
Posts: 2381
Location: Everywhere you're not.

PostPosted: Sat Jul 24, 2004 10:35 pm    Post subject: Reply with quote

Correct me if I'm wrong, but I believe you're using the old variable naming convention. Instead of using $submit, use $_POST['submit'], or change "register_globals" in the php.ini file to "on."
_________________
Bienvenidos!
Back to top View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
aprelium-beta
-


Joined: 24 Jun 2004
Posts: 383

PostPosted: Sun Jul 25, 2004 1:19 am    Post subject: Re: Error 404 when using PHP_SELF Reply with quote

MetroSpectre,

Your code is using the old PHP variable names convention.
* Solution 1: If you don't want to change your code, open php.ini and set register_globals to on
* Solution 2: change $PHP_SELF with $_SERVER['PHP_SELF'] and $submit with $_POST['SUBMIT'].

More information is available by searching this forum for 'undefined variable' or in http://www.php.net/reserved.variables .
_________________
Beta Testing Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
MetroSpectre
-


Joined: 07 May 2004
Posts: 3

PostPosted: Sun Jul 25, 2004 2:23 am    Post subject: Reply with quote

Thanks folks, that worked. :)

I also tried doing this, just for the heck of it (instead of $_SERVER['PHP_SELF']):

$PHP_SELF=$HTTP_SERVER_VARS['PHP_SELF'];

Which works in this:

<form method="post" action="<?php echo $PHP_SELF ?>">

Is that ok? What is the difference between $_SERVER and $HTTP_SERVER_VARS?

(note that I just edited this post because I found that it does work both ways - I just didn't catch all the PHP_SELF's while trying this in code :) )
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Jul 27, 2004 12:24 am    Post subject: Reply with quote

MetroSpectre,

$_SERVER is the new way of calling $HTTP_SERVER_VARS since PHP 4.1.0. $HTTP_SERVER_VARS is still available for backward compatibily, but it is preferred to use $_SERVER instead for any new code you write.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
MetroSpectre
-


Joined: 07 May 2004
Posts: 3

PostPosted: Tue Jul 27, 2004 1:24 am    Post subject: Reply with quote

Thank you. :) I think that I'll do things that way then in the future.
Back to top View user's profile Send private message
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