NEWBIE Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ozode
Forum Newbie
Posts: 1
Joined: Thu Sep 03, 2009 9:36 am

NEWBIE Question

Post by ozode »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am new to PHP and I am working on my on site now. I am trying to query the database and my code is not working. Please help!!! I have included my code if anyone can see a problem with my code I will try all things.

Code: Select all

<?php
 
 
$link = mysql_connect("mysql", "USERNAME", "PASSWORD");
mysql_select_db("asianbeachhouse booking");
 
 
if (!$link) 
{
die('Could not connect: ' . mysql_error());
}
else
{
$Query = mysql_query("SELECT Count( reservation.RoomID ) AS CountOfRoomID,
reservation.RoomID
FROM reservation
WHERE ((((reservation.RDate) >= '$checkindate')
AND ((reservation.RDate) <= '$checkoutdate'))
AND ((reservation.Availability) = 'Vacant'))
GROUP BY reservation.RoomID;
$RAvail = mysqli_query($link,$Query);
$NumResAvail = mysqli_num_rows($RAvail)");
 
 
echo "<b>$NumResAvail Rooms Available</b>";
 
?>
 
<table border="1">
<tr>
<th>Count of RoomID</th>
<th>RoomID</th> 
</tr>
 
<?php
 
while ($Row = mysqli_fetch_assoc($RAvail))
{
echo '<tr>';
echo '<td>' . $Row['CountOfRoomID'] . '</td>';
echo '<td>' . $Row['RoomID'] . '</td>';
echo '</tr>';
}
?>
</table>
<?php
mysqli_free_result($RAvail);
mysql_close($link);
}
?>

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: NEWBIE Question

Post by pickle »

You can't have a database name with spaces in it. Also, notice how the syntax highlighting is messed up after you define your query?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply