0

When I try to submit a stock symbol for a quote I get the following error:

Not Found

The requested URL /displayquote_form.php was not found on this server.

My form code is:

<!DOCTYPE html>

<html>

<body>

<form action="displayquote_form.php", method = "post">
  Enter Symbol Here<br>
  <input type="text" name="symbol"><br> <br>
  <input type="submit" value="Submit">
</form>

</body>
</html>

The file "displayquote_form.php" is in the views folder, just like my quote.php form. It seems like the form is looking for displayquote_form.php in a folder other than views. Is this the problem?

1

As a general rule, a browser cannot access files outside the document root. This is one of 132,000 articles that Mr. Google supplied when asked. php is not likewise constrained because it runs on the server. So displayquote_form.php needs to be located in the public directory (or perhaps a new directory under public and properly pathed). This is consistent with the distro code. The form action in "login_form.php" (a view) is "login.php" (a controller), which lives in public. Generally speaking, when the instructions call for a "controller", it should live in public (or a subdir), and when it calls for a "view" it should live in views. My apologies for the bad answer.

9
  • I am still having problems with this. I would like to use a relative URL so I entered: "<form action="../views/displayquote_form.php", method = "post">". The initial "../" is to step back into the pset7 directory and then "/views/" puts me into the folder with my file. – Brendan Rafferty Jul 9 '16 at 20:13
  • I also tried the absolute URL with similar results: "<form action= "ide50-gerardrafferty.cs50.io/../views/displayquote_form.php", method = "post">". Is this a permissions issue? These are in the view so it should be chmod 744 ... correct? – Brendan Rafferty Jul 9 '16 at 20:16
  • What was I thinking? (Not thinking obviously!) Sorry for the misdirect, working on a corrected answer now. As a general rule you cannot access files outside your document root. – DinoCoderSaurus Jul 9 '16 at 22:23
  • Are you saying I somehow scrambled the structure of my folders in the distribution code? While I am not above that kind of screw-up, I checked the original zip file and the file structure looks the same (pset7 has the following folders: includes, public, vendor, views). This is the same structure (more-or-less) shown in the Walkthrough from Week 8 titled mvc5 @ 1:13. I used "apache50 start ~/workspace/pset7/public" when I initiated apache. Should I have used "apache50 start ~/workspace/pset7"? – Brendan Rafferty Jul 10 '16 at 8:03
  • Also, I was able to access files in the folders "views" and "includes" during the register part with lines like "require("../includes/config.php");" and "render("../views/quote.php")" I get a similar error to what is posted in the original question. What should my permissions be for these files? – Brendan Rafferty Jul 10 '16 at 8:25

You must log in to answer this question.

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