Page 1 of 1

Cannot upload data into database 403 error

PostPosted: 18. January 2017 22:03
by michaelgoude
Hi

I am trying to take data from a form and using php code insert it into a database but I get the following (see below); I have included the code below the error message, I can connect the the database OK and read values out it but not seem to write values to the database.

Thanks


Error Message Retunted......

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28



PHP Code from Web Page;
<?php
session_start();
include('../include/db_connect.php');
if(!isset($_SESSION['user_id'])){
header('Location: blogadmin.php');
exit();
}
if(isset($_POST['submit'])){
//get blog data
$title = $_POST['title'];
$body = $_POST['body'];
$category = $_POST['category'];
$title = $db->real_escape_string($title);
$body = $db->real_escape_string($body);
$user_id = $_SESSION['user_id'];
$date = date('Y-m-d G:i:s');
$body = htmlentities($body);
if($title && $body && $category){
$query = $db->query("INSERT INTO posts (user_id, post_title, content, cat_id, date) VALUES('$user_id', '$title', '$body', '$category', '$date')");
if($query){
echo "Post Added";
}else{
echo "Error";
}
}else{
echo "Missing Data";
}
}
?>

Re: Cannot upload data into database 403 error

PostPosted: 19. January 2017 12:05
by Nobbie
Its not a question of your PHP Code, it is a question of the requested PHP script (the whole file). See this error message:

You don't have permission to access the requested object. It is either read-protected or not readable by the server


Apache cannot open the requested file. As you dont tell us anything about that file (i.e. filename, path, where is stored, how looks the URL, etc. etc.), i dont have a clue what is going wrong, but anyway, it is NOT the contents of the file, it is the file itself which cannot be opened by Apache. I guess you applied an improper action-TAG in a form or so.