whats wrong with this query!!!!!!!!!!!!

This is a discussion on whats wrong with this query!!!!!!!!!!!! within the Using PHP with SQL databases (alt.php.sql) forum.

whats wrong with this query!!!!!!!!!!!!

Postby nutan.sarkale on Mon Dec 01, 2008 4:16 pm

Hey hi,

Can any one help me out with this im getting query empty as error.
Can u plz tell me what is wrong in this code?

<?php

$con=mysql_connect("127.0.0.1","root","-------");

if(!$con)
{
die('Could not connect: '. mysql_error());
}
mysql_select_db("test",$con);

echo "<B>CUSTOMER RECEIPT</B>";

//$hotel_id= $_POST['33977'];

$sql = mysql_query("Select
h.hotel_name,h.room_price_per_nyt,r.end_date,r.start_date
FROM hotel_info h,reserve_hotel r
WHERE hotel_id=['33977']
AND h.hotel_id (+)= r.hotel_id") ;

echo "<table border='1'>
<tr>
<th>Name</th>
<th>Room_price_per_nyt</th>
<th>start_date</th>
<th>end_date</th>
</tr>";

$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
//printf("ID: %s <br> Name: %s <br> Rating: %s <br>
Room_price_per_nyt: %s <br>", $row[0], $row[1], $row[2], $row[3]);
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "</tr>";
}
echo"</table>";

if(!mysql_query($sql,$con))
{
die('Error:' . mysql_error());
}
mysql_close($con)
?>
nutan.sarkale
 
Posts: 1
Joined: Mon Dec 01, 2008 4:16 pm

Re: whats wrong with this query!!!!!!!!!!!!

Postby Captain Paralytic on Tue Dec 02, 2008 4:04 am

On 1 Dec, 23:16, nutan.sark...@gmail.com wrote:
> Hey hi,
>
> Can any one help me out with this im getting query empty as error.
> Can u plz tell me what is wrong in this code?
>
> >
> $con=mysql_connect("127.0.0.1","root","-------");
>
> if(!$con)
>   {
>       die('Could not connect: '. mysql_error());
>   }
> mysql_select_db("test",$con);
>
>   echo "CUSTOMER RECEIPT";
>
> //$hotel_id= $_POST['33977'];
>
> $sql = mysql_query("Select
> h.hotel_name,h.room_price_per_nyt,r.end_date,r.start_date
> FROM hotel_info h,reserve_hotel r
> WHERE hotel_id=['33977']
> AND h.hotel_id (+)= r.hotel_id") ;
>
> echo  "
>
>
>
>
>
> ";
>
> $result = mysql_query($sql) or die(mysql_error());
> while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
>     //printf("ID: %s
Name: %s
Rating: %s

> Room_price_per_nyt: %s
", $row[0], $row[1], $row[2], $row[3]);
> echo "";
> echo "";
> echo "";
> echo "";
> echo "";
> echo "";}
>
> echo"
NameRoom_price_per_nytstart_dateend_date
" . $row[0] . "" . $row[1] . "" . $row[2] . "" . $row[3] . "
";
>
> if(!mysql_query($sql,$con))
> {
>     die('Error:' . mysql_error());}
>
> mysql_close($con)
> ?>

What do you mean by "query empty as error"? Could you please post the
exact error message?

Also, I am not familiar with the construction "h.hotel_id (+)=
r.hotel_id". What does (+)= do?
Captain Paralytic
 
Posts: 616
Joined: Tue Sep 19, 2006 6:56 am

Re: whats wrong with this query!!!!!!!!!!!!

Postby nc on Thu Dec 04, 2008 1:47 pm

On Dec 1, 3:16 pm, nutan.sark...@gmail.com wrote:
>
> Can any one help me out with this im getting query empty as error.
> Can u plz tell me what is wrong in this code?

Nothing is wrong with the code, it's just that your query is
malformed.

> $sql = mysql_query("Select
> h.hotel_name,h.room_price_per_nyt,r.end_date,r.start_date
> FROM hotel_info h,reserve_hotel r
> WHERE hotel_id=['33977']
> AND h.hotel_id (+)= r.hotel_id") ;

There seem to be at least two SQL syntax errors here:

1. WHERE hotel_id=['33977'] (square brackets don't belong here), and

2. h.hotel_id (+)= r.hotel_id (what's the (+) for?)

Cheers,
NC
nc
 
Posts: 976
Joined: Tue Dec 28, 2004 4:57 pm


Return to Using PHP with SQL databases (alt.php.sql)

Who is online

Users browsing this forum: No registered users and 0 guests