I am a newbie to PHP and practising few php codes. I installed xampp 1.8.31 and mysql db 5.5.53 (separate from Xampp) and apache using xampp. I was doing some php coding and below is my code. I am trying to submit a sample text but when I try to do it, I get the following error.
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.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19
My php codes is as follows
=========================
- Code: Select all
<html>
<head>
<title> Add Joke </title>
</head>
<body>
<?php
if (isset ($_GET['addjoke'])): // If the user wants to add the joke
?>
<form action="<?$_SERVER['PHP_SELF']?>" method="post">
<p> Type your joke here: <br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea><br />
<input type="submit" name="submitjoke" value="Submit" />
</p>
</form>
<?php
else: // Default page display
//Connect to the database
$dbcnx =@mysqli_connect("localhost","phpmysql","phpmysql","testmysql");
if (! $dbcnx) {
die ('<p> Unable to connect to database at this time </p>');
}
// If a joke has been submitted , add it to the database
if (isset($_POST['submitjoke'])) {
$sql = "insert into jokes (joketext,jokedate) values ('$_POST[joketext]','CURDATE()')";
if (@mysqli_query($dbcnx,$sql)){
echo ('<p> Your Joke has been added successfully.</p>');
} else {
echo ('<p> Error in writing the joke to the database. mysqli_error() </p>');
}
}
echo ('<p> Here are all our jokes in the database. </p>');
//Request for all jokes in the database.
$result=@mysqli_query($dbcnx,"select joketext from jokes");
if(!$result) {
die ('<p> Error in performing query.' .
mysqli_error($dbcnx) . '</p>');
}
//Display the text of each joke in the paragraph
while ($row=mysqli_fetch_array($result)){
echo ('<p>' . $row['joketext'] . '</p>');
}
//When clicked , this link will load this page with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
'?addjoke=1"> Add a Joke ! </a></p>');
endif;
?>
</body>
</html>
The code is successful without any syntax problem. I googled for this error and was asked to provide "Require All granted" . I provided in httpd.conf file but still the same error. I am getting below error when I refer to error log.
[Sun Dec 01 16:13:58.575798 2013] [core:error] [pid 4968:tid 1764] (20024)The given path is misformatted or contained invalid characters: [client ::1:52661] AH00127: Cannot map POST /website/%3C?$_SERVER['PHP_SELF']?%3E HTTP/1.1 to file, referer: https://localhost/website/addjokes.php?addjoke=1
Can anyone guide me where I am making mistake and what needs to be done.
[edit by Altrea: added code-BBTags to make this post more readable]