TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-13-2009, 03:09 AM   #1 (permalink)
The Visitor
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
drolex is on a distinguished road
Default check rental item availability PHP MySQL

I am making a scheduling application for a rental company. They make reservations and rent out items. When they try to make a reservation, I need to check each item's availability. I've tried multiple ways. Let me show you my latest attempt.

An example row from the database looks like this:
id: "1"
customer: "Drolex"
dateList: "20090710 20090711 20090712 20090713"
toys: "1 2"
phone: "5555555"
message: "This is a message."

They enter the first and last date the item will be in use. I create a string with those dates and all dates between. The dates are separated by a space in the string and they are of the form year.month.day. I do a similar thing with the selected items (toys).

PHP check availability code:
PHP Code:
asort($toyList,SORT_NUMERIC);
$numToys count($toyList);

for(
$i=0;$i<$numToys;$i++){
    
$dateCount $dateFirst;
    while(
$dateCount <= $dateLast){
        
$sql_check "SELECT id FROM scheduledRentals WHERE toys IN('$toyList[$i]') AND dateList IN('$dateCount')";
        
$result mysql_query($sql_check);
        if(
mysql_num_rows($result) > 0){
            echo 
"Availability problem exists.";
            exit();
        }
        
$dateCount++;
    }

It's not working because I never get the message about an availability problem and the reservation is submited.

I think the problem is within the MySQL search (WHERE) technique. It doesn't give an error or warning.

Do you see an easy fix? Do you have a better method for either storing or checking date overlaps based on first and last date?

Last edited by drolex : 07-13-2009 at 08:24 AM.
drolex is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
Help on PHP MYSQL Forms Input deesudesu Absolute Beginners 1 03-20-2009 10:50 AM
Help On Php N Mysql deesudesu Absolute Beginners 5 03-13-2009 04:26 AM
how to call mysql procedures in php??? gptArun Absolute Beginners 7 06-05-2008 08:13 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM


All times are GMT. The time now is 08:38 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design