Apache causing CPU to spike when POSTing

Hello all. I've built a SAMP server on Solaris 10 using Apache 2.2.9 and PHP 5.2.6

For the most part everything seems to be working except when I post form data, Apache causes the CPU to max out. Sometimes the script will complete about 40 seconds later. Other times I have to stop Apache to get the CPU under control.

Memory use is not effected only the CPU.

I wrote 4 simple PHP scripts to try and isolate the problem. The scripts are called: burt1.php, burt2.php, burt3.php and burt4.php

(Named after some Burt's Bees I have on my desk!)

The point of the scripts is to gather two numbers (burt1), write them to MySQL (burt2), read previously entered numbers and ask you to pick one (burt3), pass this picked number to burt4.php.

Burt4 will read the database where the picked number is, retrieve it and the number marked as "second" in that row, add them together and display the result.

Simple stuff.

Burt1 and Burt2 run fine.

When I select a number in burt3 and click submit, Apache goes nuts and maxes out the CPU.

I never get to the burt4 script and have to kill Apache to get the CPU under control.

Any thoughts or suggestions on why the CPU is maxing out would be very much appreciated.

Below I have posted the 4 scripts. They were quickly written in Notepad. So apologies for the poor formatting.

Thank you for your comments.
~Robert

<?php
//burt1.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
if ($dbc) {
echo "good connection to the burt database";
}else{
echo "failed to connect";
}

echo '<br>';
echo '<br>';
echo "a quick mysql form post and read test";
echo '<br>';
?>
<form action = "burt2.php" method = "POST">
<p>First number:<input type = "text" name = "first_number"/></p>
<p>Second number:<input type = "text" name = "second_number"/></p>
<p><input type = "submit"/></p>
</form>
<?php
//end of burt1 script
?>
-----------------------------------------------------------------
<?php
//burt2.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
$first_number = $_POST['first_number'];
$second_number = $_POST['second_number'];
if ($dbc){
echo "burt2 has a good database connection";
}else{
echo "failed to connect to the database";
}
echo '<br>';
echo '<br>';
echo "the first number is: $first_number";
echo '<br>';
echo "the second number is: $second_number";
echo '<br>';
echo '<br>';
$user_id = time();
$query1 = "insert into numbers (user_id, first_number, second_number) values ('$user_id', '$first_number', '$second_number')";
$result1 = mysql_query($query1);
if ($result1) {
echo "wrote to the database";
}else{
echo "write to the database, failed";
}
echo '<br>';
?>
<form action = "burt3.php">
<input type = "submit" value = "go to burt3">
</form>
<?php
//end of burt2 script
?>
------------------------------------------------------------------
<?php
session_start();
//burt3.php
//connect to MySQL and select the database
require_once('./burt_connect.php');
echo "burt 3 script";
echo '<br>';
echo "pick from the first numbers below to add the second";
$query1 = "select first_number from numbers order by first_number ASC";
$result1 = mysql_query($query1);
while ($row=mysql_fetch_array($result1)) {
$pick = $row[first_number];
echo '<br>';
echo "a number you can use is: $pick";
}
echo '<br>';
$_SESSION['whatever'] = "solaris";
if (mysql_close($dbc)) {
echo "connection closed";
echo '<br>';
} else {
echo "connection not closed";
echo '<br>';
}
?>
<form action = "burt4.php" method = "POST">
<p>select a first number: <input type = "text" name = "number"></p>
<p><input type = "submit"></p>
</form>
<?php
//end of burt3 script
?>
-------------------------------------------------------------------
(never get to this script)
<?php
session_start();
//burt4.php
$value = $_SESSION['whatever'];
echo "burt 4 script";
echo '<br>';
echo "the session variable value is: $value it should be solaris";
echo '<br>';
$get_number = $_POST['number'];

//connect to MySQL and select the database
require_once('./burt_connect.php');
if ($dbc) {
echo "good connection to the database";
}else {
echo "no good connection to the database";
}
echo '<br>';
$query1 = "select * from numbers where first_number = '$get_number'";
$result1 = mysql_query($query1);
while ($result1) {
$first_number = $row[first_number];
$second_number = $row[second_number];
}
$total = $first_number + $second_number;
echo "the numbers we are going to add are: $first_number and $second_number";
echo '<br>';
echo "they equal: $total";
echo '<br>';
echo "end of burt4 script";
?>

First, please encapsulate your scripts in

 tags so we can read them. 

Second, is Apache configured to use PHP as a module or as CGI?

Third, this line here might give some trouble:

$pick = $row[first_number];

first_number is neither a symbol nor string. What is it?

Otheus:

Thanks for responding. Sorry about not using the code tags. That was my first time posting code and did not know about them.

Apache is configured as a CGI. Here is the Apache configure command I used:

'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql' '--with-curl=/usr/local/lib' '--with-curlwrappers' '--enable-fastcgi' '--enable-force-cgi-redirects'

first_number is a number. I tried it with both single and double quotes - got the same result each time, a maxed out CPU.

Thanks for pointing the missing quotes.

The Apache2 httpd.conf includes the following lines:

LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php .phtml

ok, good. those lines with $row[first_number] don't make any sense to me.