/    Sign up×
Community /Pin to ProfileBookmark

PHP in HTML

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.

[CODE]

<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>
[/CODE]

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 ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@mahfoozApr 27.2007 — try to write your php code at the top of your form
Copy linkTweet thisAlerts:
@jludtauthorApr 27.2007 — 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.
×

Success!

Help @jludt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...