Jump to content

PHP HTTP 500 Error


sood.rahul

Recommended Posts

Hi All,

 

I know it is a silly error but I am very new to PHP (only 2 days!!!) & unable to resolve this. I have seen a lot of resolutions online for example:

 

1) Copying the "php5isapi.dll" file to the PHP directory & under "Program Files" as well.

2) Copying the "favicon.ico" file

 

etc etc

 

Before I could elaborate the issue, please note that I am a Windows user - Windows XP (I know its not the best of the OS's to work with!!!)

 

When initially I started getting the issue, I checked the "error.log" file under "C:\Program Files\Apache Software Foundation\Apache2.2\logs" & following is what I saw:

 

-----------------------

 

[sun Sep 18 14:13:25 2011] [notice] Server built: Sep  9 2011 10:26:10

[sun Sep 18 14:13:25 2011] [notice] Parent: Created child process 4420

[sun Sep 18 14:13:25 2011] [notice] Child 4420: Child process is running

[sun Sep 18 14:13:25 2011] [notice] Child 4420: Acquired the start mutex.

[sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting 64 worker threads.

[sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting thread to listen on port 80.

[sun Sep 18 14:14:55 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico

 

[sun Sep 18 14:21:37 2011] [notice] Server built: Sep  9 2011 10:26:10

[sun Sep 18 14:21:37 2011] [notice] Parent: Created child process 7976

[sun Sep 18 14:21:37 2011] [notice] Child 7976: Child process is running

[sun Sep 18 14:21:38 2011] [notice] Child 7976: Acquired the start mutex.

[sun Sep 18 14:21:38 2011] [notice] Child 4420: Released the start mutex

[sun Sep 18 14:21:38 2011] [notice] Child 7976: Starting 64 worker threads.

[sun Sep 18 14:21:39 2011] [notice] Child 4420: All worker threads have exited.

[sun Sep 18 14:21:39 2011] [notice] Child 4420: Child process is exiting

[sun Sep 18 14:21:39 2011] [notice] Child 7976: Starting thread to listen on port 80.

[sun Sep 18 14:21:52 2011] [error] [client 127.0.0.1] File does not exist: C:/Rahul/Personal/Web Development/favicon.ico

 

----------------------

 

Then I created an icon file and named it "favicon.ico" & placed it in the following destinations:

 

1) C:/Rahul/Personal/Web Development/ and

2) C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/

 

but to no avail

 

But interestingly & surprisingly, the error.log file stopped giving any of the above error messages but I still get the HTTP Error.

 

Following is the error message that I get on the browser:

 

--------------------------

 

Server error

The website encountered an error while retrieving http://localhost/Forms/insert%20data.php. It may be down for maintenance or configured incorrectly.

Here are some suggestions:

Reload this webpage later.

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

 

--------------------------

 

Now, just to let you know which php I am using, so, just to let you know, I just copied the html & php from http://www.w3schools.com/PHP/php_mysql_insert.asp. Following are they:

 

HTML:

----------------------------

<html>

<body>

 

<form action="insert data.php" method="post">

Firstname: <input type="text" name="firstname" />

Lastname: <input type="text" name="lastname" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

 

</body>

</html>

-----------------------------

 

PHP

 

-----------------------------

 

<?php

 

$con = mysql_connect("localhost","root","orange");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

echo "Connection established";

 

mysql_select_db("my_db", $con);

 

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST['firstname']','$_POST['lastname']','$_POST['age']')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added with name: " $_POST[firstname] $_POST[lastname];

 

mysql_close($con)

 

?>

 

-------------------------

 

I hope someone is able to help me in this & I guess I have mentioned everything I could to explain the error!

 

Many thanks in advance!

Rahul

Link to comment
Share on other sites

Hi,

 

I just added these lines above my php code (please see below)  but still nothing has happened. No error messages are displayed and nothing has been added to the "error.log" file under "C:\Program Files\Apache Software Foundation\Apache2.2\logs".

 

I am still getting the same error message.

 

Am I doing something wrong here? Did you want me to add these lines somewhere else? Can adding these lines at the top turn on error checking?

 

<?php

 

ini_set('display_errors',1);

error_reporting(E_ALL); 

 

$con = mysql_connect("localhost","root","orange");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

echo "Connection established";

 

mysql_select_db("my_db", $con);

 

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST['firstname']','$_POST['lastname']','$_POST['age']')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added with name: " $_POST[firstname] $_POST[lastname];

 

mysql_close($con)

 

?>

Link to comment
Share on other sites

ok, you first need to make suret hat your server is operating correctly. what are you using for your php / apacher server. if you are using windows i would advise using WAMP or something similar. if you have only started doing this then maybe it would be a good idea not to dig yourself into a deeper hole trying to fix a server that you may or may not have corrupted without knowing about it. Installing wamp is extremely easy as most of it is done for you. then you just drop you php files into the wamp/htdocs folder.

 

Link to comment
Share on other sites

Hi,

 

Yes, I am using Apache & it seems it is working correctly. But again, as you have rightly mentioned, I might have corrupted something which I might not be sure of.

 

Just to let you know I am getting this issue in all the HTML forms where I used the POST method to send data from the forms to my PHP.

 

Other standalone phps are working fine.

 

Can you think of any resolution on Apache? Am not sure of WAMP - not even heard of it. And as Apache is widely used, I would like to stick to it. What do you suggest?

Link to comment
Share on other sites

WAMP is apache. It is a bundle of everthing you need. is stands for Windows Apache Mysql Php. But as you have said that everything is working i have had a look at the code you are using. I have corrected some mistakes for you:

<?php

ini_set('display_errors',1);
error_reporting(E_ALL);   

$con = mysql_connect("localhost","root","orange");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
echo "Connection established";

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('".$_POST['firstname']."',''".$_POST['lastname']."',''".$_POST['age']."')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added with name: ". $_POST[firstname].' '. $_POST[lastname];

mysql_close($con)

?>

so replace yours with that.

One of the problems you had was trying to use php within the sql statement. You need to make sure that the string does not escape. ie

<?php
$sql ="SELECT * FROM $_POST["table"]";

// will actually translate to : $sql ="SELECT * FROM $_POST["

this is because the double quotes tell the php that this is the end of the string. To get around this you use concatination by adding the '.' around your variable:

 

<?php
$sql ="SELECT * FROM ". $_POST["table"] ." ";

 

this is by no means an indepth explination, but a quick search for string concatination in php on google should point you in the right direction

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.