dubc07 Posted September 2, 2008 Share Posted September 2, 2008 I'm having troubles with the second query even though there is no match for starttime and endtime it pulls query and gives error Any help is good. Let's say i wanted to book from 600 to 1500 which is 6am to 3pm and there is a booking from 1600 to 2000 This part stops the booking when it should allow WHY? <?php $p1 = 'SELECT COUNT(*) AS counts FROM rentem WHERE `month`="'.$month.'" AND `day`="'.$day.'" AND `name`="'.$username.'" AND ( "'.$starttime.'= starttime AND '.$endtime.' = endtime" OR endtime = '.$endtime.' OR starttime= '.$starttime.' )'; $sql = mysql_query($p1); $counts = mysql_result($sql, 0, 'counts'); if ($counts > 0) { die('<table width="475" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="24"><img src="images/error_mess.gif" width="35" height="28"></td> <td width="283">Error! </td> </tr> </table>'); } ?> FULL CODE <?php // This is for Central Standard Time ini_set('date.timezone','America/Chicago'); include conection; ?> <?php $starttime = 600; $endtime = 1500; $month = 'August'; $day = '30'; $plane = '1'; /// On the database there is an entry from starttime 1600 to endtime 2000//// $username = ( $data['fullname']); ////user define checks database for time overlapping on user end THIS WORKS GREAT/// $p = 'SELECT COUNT(*) AS count FROM rentem WHERE `month`="'.$month.'" AND `day`="'.$day.'" AND `name`="'.$username.'" AND ( "'.$starttime.'"BETWEEN starttime AND endtime OR "'.$endtime.'" BETWEEN starttime AND endtime OR starttime BETWEEN "'.$starttime.'" AND "'.$endtime.'" OR endtime BETWEEN "'.$starttime.'" AND "'.$endtime.'" OR starttime & endtime BETWEEN "'.$starttime.'" AND "'.$endtime.'" )'; $sql = mysql_query($p); $count = mysql_result($sql, 0, 'count'); if ($count > 0) { die('<table width="475" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="24"><img src="images/error_mess.gif" width="35" height="28"></td> <td width="283">Error! </td> </tr> </table>'); } ////THIS IS THE PROBLEM Even though there is no match for starttime and endtime it pulls one query and gives error?///// $p1 = 'SELECT COUNT(*) AS counts FROM rentem WHERE `month`="'.$month.'" AND `day`="'.$day.'" AND `name`="'.$username.'" AND ( "'.$starttime.'= starttime AND '.$endtime.' = endtime" OR endtime = '.$endtime.' OR starttime= '.$starttime.' )'; $sql = mysql_query($p1); $counts = mysql_result($sql, 0, 'counts'); if ($counts > 0) { die('<table width="475" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="24"><img src="images/error_mess.gif" width="35" height="28"></td> <td width="283">Error! </td> </tr> </table>'); } ?> Link to comment https://forums.phpfreaks.com/topic/122414-query-problems/ Share on other sites More sharing options...
BlueSkyIS Posted September 2, 2008 Share Posted September 2, 2008 what is the error? Link to comment https://forums.phpfreaks.com/topic/122414-query-problems/#findComment-632121 Share on other sites More sharing options...
webxan Posted September 2, 2008 Share Posted September 2, 2008 try changing the queries to these $p = 'SELECT COUNT(*) AS count FROM rentem WHERE `month`="'.$month.'" AND `day`="'.$day.'" AND `name`="'.$username.'" AND ( starttime BETWEEN "'.$starttime.'" AND "'.$endtime.'" OR endtime BETWEEN "'.$starttime.'" AND "'.$endtime.'" OR starttime & endtime BETWEEN "'.$starttime.'" AND "'.$endtime.'" )'; $p1 = 'SELECT COUNT(*) AS counts FROM rentem WHERE `month`="'.$month.'" AND `day`="'.$day.'" AND `name`="'.$username.'" AND ( endtime = '.$endtime.' OR starttime= '.$starttime.' )'; Link to comment https://forums.phpfreaks.com/topic/122414-query-problems/#findComment-632188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.