1

I have created a php script and saved it as script.php, located in the /var/www directory. I also have index.html file which has a form which requires the user to enter a value and submit with the code

<html><body><form action="script.php" method="post">
name<input type="text name="fname"">
<input type="submit">
</form>
</body></html>

for testing purposes, i have set my script.php file to be like

<?php
echo "Could not read name";
?>

When i enter the url on the browser, i get the form and on clicking submit, it responds by saying the url http://localhost/script.php was not found. i would like to know the reason why this is so. The question extends to why i can run the php script on its own when i move it from /var/www to home folder and run it as php -f script.php yet when i paste the url http://localhost/script.php , it reports that the url has not been found

3
  • check the error log in /var/log/apache2 Sep 2, 2013 at 13:34
  • 1
    @GeraldSchneider what should i check for
    – sosytee
    Sep 2, 2013 at 13:35
  • 1
    anything related to "script.php" Sep 2, 2013 at 13:36

2 Answers 2

3

Hi this what I have done and I have got success with your Idea.

here this is what I have done ,

script.php

<html>
<body>
<?php
echo " welcome "

?>
</body>
</html>

clickhere.html

<html><body><form action="script.php" method="post">
name<input type="text name="fname"">
<input type="submit">
</form>
</body></html>

I have placed that code with sudo gedit and written that code and saved at the location of /var/www/.

Then I have opened my browser ,and typed in my browser as 127.0.0.1/clickhere.html

then I have got it enter image description here

and then I have clicked at that button enter image description here

4
  • I am using Ubuntu server, sorry i did not clarify, therefore i have used vi editor, does that create a problem
    – sosytee
    Sep 2, 2013 at 13:56
  • No editor is not at all a problem.give a try with chmod 755 /var/www/script.php and chmod 755 /var/www/clickhere.html and then try again.
    – Raja G
    Sep 2, 2013 at 13:58
  • Instead of using 127.0.0.1 can I connect to node via its static IP? @Ten-Coin
    – alper
    May 16, 2018 at 16:42
  • @Alper Yes you can.
    – Raja G
    May 17, 2018 at 4:47
0

try this for your php echo statement

echo " welcome " . $_POST['fname'];

Also your HTML has quote mismatch for the input tag

<input type="text" name="fname">

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .