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 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 , it reports that the url has not been found

3

2 Answers

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

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"> 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy