Jump to content

403 adress forbidden on insert data


MrLoefjo

Recommended Posts

Hiya, i have a problem inserting data in my blog project, using XAMPP. I made a simple page so far, where you can view blog posts and comments. I added some data using phpmyadmin, and now i tried to make an option to add comments to blog post via the page. Unfortunately, whenever i try to do it, i get 403 access forbidden. Here is the code for viewing specific entry and comment section:

 

require("config.php");

if(isset($_GET['id']) == TRUE) {
if(is_numeric($_GET['id']) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir);
}
else {
$validentry = $_GET['id'];
}
}
else {
$validentry = 0;
}

if($_POST['submit']) {
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$sql = "INSERT INTO blogcomment(blog_id, Date,
Username, Comment) VALUES(" .
$validentry . ", NOW(), '" . $_POST['name']
. "', '" . $_POST['comment'] . "');";
mysql_query($sql);
header("Location: http://" . $HTTP_HOST
. $SCRIPT_NAME . "?id=" . $validentry);
}
else {
// code will go here
}

require("header.php");


if($validentry == 0) {
$sql = "SELECT blog.* FROM blog ".
"ORDER BY Date DESC ".
"LIMIT 1;";
}
else {
$sql = "SELECT blog.* FROM blog WHERE blog.id = $validentry ORDER BY Date ASC
LIMIT 1";

}

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo "<h2>" . $row['Title'] . "</h2><br />";
echo "</a> - Posted on " .
date("D jS F Y g.iA", strtotime($row['Date'])) ."</i>";
echo "<p>";
echo nl2br($row['Entry']);
echo "</p>";

$commsql = "SELECT blogcomment.* FROM blogcomment WHERE blogcomment.blog_id = $validentry ORDER BY Date DESC";
$commresult = mysql_query($commsql);
$numrows_comm = mysql_num_rows($commresult);

$numrows_comm = mysql_num_rows($commresult);
if($numrows_comm == 0) {
echo "<p>No comments.</p>";
}
else {
$i = 1;
while($commrow = mysql_fetch_assoc($commresult)) {
echo "<a name='comment" . $i . "'>";
echo "<h3>Comment by " . $commrow['Username'] . " on " .
date("D jS F Y g.iA",
strtotime($commrow['Date'])) . "</h3>";
echo $commrow['Comment'];
$i++;
}
}
?>
<h3>Leave a comment</h3>
<form action="<?php echo $SCRIPT_NAME
. "?id=" . $validentry; ?>" method="post">
<table>
<tr>
<td>Your name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comment" rows="10" cols="50"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add comment"></td>
</tr>
</table>
</form>

<?php

require("footer.php");
?>

 

Thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/243970-403-adress-forbidden-on-insert-data/
Share on other sites

Your problem is due to the old and outdated use of the $HTTP_HOST and $SCRIPT_NAME variables in your code.

 

Those were depreciated in php4.1, over 9 years ago, in favor of $_SERVER['HTTP_HOST'] and $_SERVER['SCRIPT_NAME']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.