>Thanks for everyones help yesterday but nI have come up against a problem >(as I am new). I have created my document as detailed below with notes. I >can see from the form that I have connected to the server, accessed the >correct database, created the statment and executed it. The problem is how >to display the information - as far as I can understand from yesterday if >the result is 0 then the villa is available. So what I need to do is if the >result = 0 display villa available and if the result is greater than 0 then >display villa not available . I know that the variables are getting to the >query as if I change the echo $result; to $sql; and key in 3 as the id and >2 dates in the form I get the following: > >SELECT COUNT(*) FROM bookings WHERE ('2002-04-04') BETWEEN booking_start AND >booking_end OR ('2002-04-10')BETWEEN booking_start AND booking_end AND >villa_id = ('3') > >So, corrcet me if I am wrong but the query is working its just i cannot see >anything. I have spent hours on this today, reading books and looking at the >list. I hope that once I have done one good script I can then start to >understand it and create more :-) > >Thanks for all your help > > >Ray > > ><html> > <body> > <?php > > if ($submit) { > > // open connection to database > > $db = mysql_connect("localhost", "matrix", "matrix");
Add "or error_log(mysql_error())" to the end of this, so if your database goes down or something you'll have a record of it in your Apache log. > > // pick database to use > > mysql_select_db("matrix",$db); Same here in case some goofball deletes the whole matrix database or something. > > // create the SQL statement > > $sql = "SELECT COUNT(*) FROM bookings WHERE ('$book_start_date') BETWEEN >booking_start AND booking_end OR ('$book_end_date')BETWEEN booking_start AND >booking_end AND villa_id = ('$place')"; Get rid of all the () except for count(*). The rest of them are bogus. > // execute the SQL statement > > $result = mysql_query($sql); > > // display the information > > echo $result; NO. $result is *NOT* your information. If your SQL is broken, you'll get nothing output here. You should again have: or error_log(mysql_error()) at the end of the mysql_query() statement. If everything goes well, though, $result *still* won't be the information you want. It will be a "result identifier" That's a fancy way of saying it's like a little ticket at the meat counter in your grocery store so you know whose turn it is. You need to use http://php.net/mysql_fetch_row (or similar functions) to get your actual data. In this case, since you only get one answer, I would just use: echo mysql_result($result, 0, 0); to see the answer you want. Actually, it will be more like this: $taken = mysql_result($result, 0, 0); if ($taken){ echo "Villa $place is not available between $book_start_date and $book_end_date<BR>\n"; } else{ echo "Villa $place is available from $book_start_date to $book_end_date<BR>\n"; } mysql_query() never returns your actual data -- It only returns an "identifier" so you can go get your data. >} else{ > > // display form > > ?> > <form method="post" action="<?php echo $PHP_SELF?>"> > Villa id number:<input type="Text" name="place"><br> > Start date:<input type="Text" name="book_start_date"><br> > End date:<input type="Text" name="book_end_date"><br> > <input type="Submit" name="submit" value="Search information"> > </form> > <?php > } > // end if > ?> > </body> > </html> > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php