PHP Code:
<?php
$connection=mysql_connect ("localhost", "spike", "9sj7En4");
if (!$connection)
{
die ('Could not Connect: '. mysql_error());
}
mysql_select_db ("My_DB", $connection) or die (mysql_error());
if(!(isset($_POST['submit_button']))){
// they did not click the button
$result = mysql_query ("SELECT * FROM Expenses") or die (mysql_error());
echo "<table border='2'>
<tr>
<th>Category</th>
<th>Date</th>
<th>Dollar Amount</th>
</tr>";
while ($row= mysql_fetch_array ($result))
{
echo "<tr>";
echo "<td>" .$row ['Category'] ."</td>" ;
echo "<td>" .$row ['Date'] ." </td>";
echo "<td>" .$row ['Dollar Amount'] . " </td>";
echo "</tr>";
}
echo "</table>";
}else{
// the form was submitted
// retrieve all the values from the form here
}
mysql_close ($connection);
?>
Now, you only have to make sure the button name in the form
is 'submit_button' for example :
HTML Code:
<form action="" method="post">
......
<input type="submit" value="GO" name="submit_button" />
</form>
Considering your new to PHP, I want to let you know using single-quotes instead
of double-quotes speeds up your script.
Regards.