Click to See Complete Forum and Search --> : PHP in HTML


jludt
04-26-2007, 04:34 PM
I am trying to retrieve information from an SQL database and return the info in/on the same .php file that has the form buttons. For some reason when I try to connect to the database my file shows up with nothing however.

<html>
<title> This is my PHP/HTML Integrated Test Page</title>
<body>
<br>
<form action="lab3a.php" method="POST">
<input type="radio" name="RadioGroup1" value="1">
Display all book records
<br>
<input type="radio" name="RadioGroup1" value="2">
Display book records where price is greater than:
<input type=text size=20 maxlength=150 name="range">
<br>
<br>
<br>
<input type=submit value="Submit Query">
<input type=reset value="Cancel">

</form>

<?php
$dbc=mysql_connect('frodo','jludt','memioth8')
or die ("Could not connect to MySQL.<br>");

mysql_select_db('jludt') or die("Could NOT Open DB.<br>");

if (!isset($_POST["RadioGroup1"])
die ("</body></html>");

if ($_POST["RadioGroup1"] = 1)
{
$query="SELECT * FROM books";
}
else
{
$query="SELECT * FROM books WHERE price > '$_POST[range]'";
}

$result=mysql_query($query);

if (mysql_num_rows($result) > 0)
{
echo "<div align=center>";
echo "<table width='50%' border=1>";
$first=TRUE;
while ($row=@mysql_fetch_array($result,MYSQL_ASSOC))
{
if ($first)
{
echo "<tr>";
foreach ($row as $key => $value)
{
echo "<th>$key</th>";
}
echo "</tr>";
$first=FALSE;
}
echo "<tr>";
foreach ($row as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
else
{
echo "No results from query.<br>";
}

mysql_close();

?>

</body>
</html>


Does anyone know why this isn't working or even possibly another way I can get information from an SQL db to show up on the same php page as teh form information???
Thanks :cool:

mahfooz
04-27-2007, 05:14 AM
try to write your php code at the top of your form

jludt
04-27-2007, 12:53 PM
thanks for the response. I tried your advice but to no avail it is still showing up as a blank page when I try to access it from a browser. I tried cutting out all the db stuff and just echoing out some statements in php and it worked fine. Has something to do with the SQL php code cause whenever I put that stuff back in it comes up blank. I even tried putting in the SQL php stuff in line by line and as soon as I tell it to connect to my db it doesn't display.