Eduardo Pinto
Eduardo Pinto

Reputation: 55

I can't get this piece of code to work -> $_SERVER['PHP_SELF'] <-

I'm trying to run a very simple script to test the "action=echo $_SERVER['PHP_SELF'];" in a HTML form (with php start and end on it but this site doesn't allow me to introduce those chars). This is the script:

<?php if(isset($_POST['submit'])) { echo "it works"; } ?>

<form name="test" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<input type="submit" name="submit" value="Submit Form">

Problem is whenever I hit the submit button I get a "Safari can't find the file" error stating that "no file exists at the address" where I run the script.

What am I doing wrong here?

Many thanks in advance for your help!

Eduardo

Upvotes: 1

Views: 1194

Answers (2)

bIgBoY
bIgBoY

Reputation: 417

You don't need to set the action attribute of the form, if you want to post data to the same page.

<form name="test" method="post"> 
  ...
  <input type="submit" name="submit" value="Submit Form" />
</form>

should do it.

Cheers!

Upvotes: 1

Mihai Matei
Mihai Matei

Reputation: 24276

Try using $_SERVER['REQUEST_URI'] instead of $_SERVER['PHP_SELF']. I think you are using mod_rewrite and that's why it cannot find the file.

Upvotes: 1

Related Questions