GT22
GT22

Reputation: 503

What is this form doing that causes an error?

Any file linked from the form in the code below causes the page to throw out this error:

Forbidden

You don't have permission to access /savetodb.php on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Code:

<div id="form">
<?php
$result = mysql_query("SELECT * FROM textdb WHERE id=1") 
or die(mysql_error());  
$fields = mysql_fetch_assoc($result);
?>
<form action="savetodb.php" method="post">
<p><a href="#">Text from DB One</a><br></p>
<br /><?php echo"<input name=\"one\" type=\"text\" id=\"one\" value=\"" .$fields['one']. "\"/>"; ?>
<br /><br />
<p><a href="#">Text from DB 2</a><br></p><br />
  <?php echo"<input name=\"two\" type=\"text\" id=\"two\" value=\"" .$fields['two']. "\">"; ?>
<br /><br />
<p><a href="#">Text from DB 3</a><br></p><br /><?php echo"<input name=\"three\" type=\"text\" id=\"three\" value=\"" .$fields['three']. "\">"; ?>
<br /><br />
<input name="submit" type="submit" value="Save"></form>
</div>

Have I missed something in the code that could be causing this? The files permissions are set to 655 (the default for my server, 777 isn't allowed).

The form imports data from the database in to editable fields, then when you click save, it should save that info back to the database. When you click save, the browser gives you the Forbidden error.

Please don't point out I should be using PDO statement, I'm still learning :/

The problem is not with the code, but with a server plugin called modsecurity. It has been disabled by my host now and works perfectly! If you are getting similar errors please contact your host, to save you a few days of trouble shooting!

Upvotes: 0

Views: 258

Answers (3)

GT22
GT22

Reputation: 503

Sorry guys, it was a problem with modsecurity as there is HTML in the form, it was blocking the file from working.

Very odd problem which my host hast fixed now.

I'll leave this here in case anyone in future is experiencing the same problems. Thanks for your help!

Upvotes: 0

JvdBerg
JvdBerg

Reputation: 21856

There are some possible causes to this:

  • the file /savetodb.php does not exists
  • the file permissions do not allow the webserver process to access the file
  • you have configured your .htaccess or virtualhost in a way that this file can not be accessed.

Upvotes: 4

Chris S.
Chris S.

Reputation: 1257

Error 404 means file not found.

Make sure the path is correct and check for rewrite-rules in .htaccess

Upvotes: 0

Related Questions