/    Sign up×
Community /Pin to ProfileBookmark

HELP! – php code to retrieve data from MySQL – not working.

Hi, i have a massive problem and have to solve it by 2moro nite…
…Got the following table:

Room table> RoomID, RoomNo, Capacity

I’ve made the code in HTML, have got a text box to enter the capacity they require – this is assigned to $capacity – and an SQL query is done to pull out a room with a bigger capacity than $Capacity.
The code does nothing – gives me a blank page!
Heres the code…if you could find a problem with it – please let me know

[COLOR=Indigo]<?
$usr = “***“;
$pwd = “*
**
“;
$db = “***“;
$host = “*
**
“;

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (mysql_error()) { print “Database ERROR: ” . mysql_error(); }

?>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

</head>

<body>

<?php

if($submitupdate) {

$Capacity = $_GET[“Capacity”];

$sql = “SELECT RoomID, RoomNo, Capacity FROM Room WHERE Capacity=>$Capacity”;

$result = mysql_query($sql,$connection)

or die(“Couldn’t execute Name SELECT query”);

//Printing Results in HTML
echo “<br><br><table border=0 align=center>”;

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo “t<tr>n”;
foreach ($line as $col_value) {
echo “tt<td>$col_value</td>n”;
}
echo “t</tr>n”;
}
?>

<table bgcolor=”white” align=”center”>
<form action=”<?php echo $PHP_SELF?>” method=”get” name=”form1″>
<table>

<tr><td><b>Capacity: </b> </td><td><input type=”int” name=”Capacity” size=40></td></tr>

<input type=”Submit” name = “submitupdate” value = “Submit Request”>

</table>
</form>
<?php } ?>
</body>

</html>[/COLOR]

Thats the code…one more thing I wnated to ask – anyone know how I could put the results into a table with each column headed with the field label. The code I’m using (see “//Printing Results in HTML” in above code) just gives me a list of rows.

THANKS

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Tommy25 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.17,
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,
)...