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