Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Availability Checker Script

  1. #1
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Availability Checker Script

    how can i check a value against a list of values stored in a seperate file (file will be included useing php include)

    for example the file wil store
    1
    2
    3
    4
    5
    and the user will enter 3 and the form iwll reply and say sorry this already exists however if the user enters a number that isnt in the list e.g. 6 it will say ok it is available, already googled for many hours with no luck and i no nex to nothing in php to d this myself... thanks

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    PHP Code:
    <?php
    $list 
    explode("\r\n",file_get_contents("info.txt"));
    if (
    array_search($_REQUEST["val"], $list) === FALSE) {
        
    $list[] = $_REQUEST["val"];
        
    $new implode ("\r\n",$list);
        
    $handle fopen("info.txt","w+");
        
    fwrite($handle,$new);
        
    fclose($handle);
    } else {echo 
    "Value already exists.";}
    ?>
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    perfect thank you but i have 1 more thing to ask, how do i echo a textfields value on the same page rather than passing the value from 1 page to another

  4. #4
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Ajax. Im bad with javascript, so you'll have to ask someone else.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by Locky View Post
    perfect thank you but i have 1 more thing to ask, how do i echo a textfields value on the same page rather than passing the value from 1 page to another
    Are you talking about doing it in "real-time" once the user hits the submit button, or are you talking about having it refresh the page, then show it?

    If the first, either using javascript (or AJAX - which is a form of javascript) would do this. I could probably help you out with this if I had more details. If; however, you are talking about the second item above, then you can do this simply in PHP.

    (Example: starting at the body of the document):
    Code:
    <body>
    <?php
    
     if (isset($_REQUEST['textfield']) && !empty($_REQUEST['textfield'])) {
       echo $_REQUEST['textfield'];
     }
    ?>
    </body>
    Hope this helps.
    Last edited by thetestingsite; 03-22-2007 at 02:48 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Are you talking about doing it in "real-time" once the user hits the submit button, or are you talking about having it refresh the page, then show it?

    If the first, either using javascript (or AJAX - which is a form of javascript) would do this. I could probably help you out with this if I had more details. If; however, you are talking about the second item above, then you can do this simply in PHP.

    (Example: starting at the body of the document):
    Code:
    <body>
    <?php
    
     if (isset($_REQUEST['textfield']) && !empty($_REQUEST['textfield'])) {
       echo $_REQUEST['textfield'];
     }
    ?>
    </body>
    Hope this helps.
    [/CODE]
    lookin like this is exactly what i want again thanks u guys all so very helpful! appreciated

  7. #7
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    well i have my script working however now i need a date format validator (DD/MM/YY) basicly if the date format is correct and the date is valid then it will continue with the rest of the script, however format is correct and date is INVALID script stop and the user will correct date, if it is also possible to help with this thank you so much
    Last edited by Locky; 03-22-2007 at 04:51 PM. Reason: addition of content

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry, did not see the edit until just now. Do you mean something like this:

    (Example, not real code snippet)
    Code:
    if ($date == "12/31/07") {
    showText();
    }
    
    else {
    showError();
    }
    If you could be a little more specific, I could probably write up the code for you or at least point you in the right direction.

    Hope this helps.
    Last edited by thetestingsite; 03-24-2007 at 12:46 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Sorry, did not see the edit until just now. Do you mean something like this:

    (Example, not real code snippet)
    Code:
    if ($date == "12/31/07") {
    showText();
    }
    
    else {
    showError();
    }
    If you could be a little more specific, I could probably write up the code for you or at least point you in the right direction.

    Hope this helps.
    i have done the script perfect now checks date input format if the input format is correct then it checks to see if it is a valid date if the date is valid it will check against the text file
    however 1 little thing for date format it is useing DD-MM-YY but i want to change to slashes instead.
    <?php
    if (preg_match('/^(\d{2})-(\d{2})-(\d{2})$/', $_REQUEST['txtDate'], $datebit)) {
    $checkthisdate = checkdate ($datebit[2], $datebit[1], $datebit[3]);
    echo ValidateDate($checkthisdate);
    ?>
    this is the bit that checks the text file for the date requested (courtesy of boxxertrumps) but now the checker now i require it to check the same date twice once for peter once for paul so iw as thinking haveing the date then after it either peter or paul so if user enter 31/12/07 it will search the text and return something like
    Peter Is Available
    Paul is Available
    however if in the text it say 31/12/07 Paul it will only return peter is available and vice versa, hope u understand
    <?php
    $list = explode("\r\n",file_get_contents("info.txt"));
    if (array_search($_REQUEST["val"], $list) === FALSE) {
    $list[] = $_REQUEST["val"];
    $new = implode ("\r\n",$list);
    $handle = fopen("info.txt","w+");
    fwrite($handle,$new);
    fclose($handle);
    } else {echo "Value already exists.";}
    ?>

  10. #10
    Join Date
    Mar 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    function CheckForDJ() {
    require(
    'config.php');
    if (
    preg_match('/^(\d{2})-(\d{2})-(\d{2})$/'$_REQUEST['txtDate'], $datebit)) {
    $checkthisdate checkdate ($datebit[2], $datebit[1], $datebit[3]);
    echo 
    ValidateDate($checkthisdate);
    } else {
    echo 
    "$invalidateformatmsg";
    }
    }



    function 
    ValidateDate($datetovalidate){;
    require(
    'config.php');
    if(
    $datetovalidate == "bool(true)"){
    requestDate();
    }else {
    echo 
    "$invaliddatemsg"; return false;
    }
    }



    function 
    requestDate()
    {
    require(
    'config.php');
    $list explode("\r\n",file_get_contents("$dbname"));
    if (
    array_search($_REQUEST["txtDate"], $list) === FALSE) {
    $list[] = $_REQUEST["txtDate"];
    $new implode ("\r\n",$list);
    echo 
    "$bookingavailable";
    } else {echo 
    "$bookingnotavailable";}
    }
    ?> 


    CheckForDJ(); 
    thetestingsite wondering if you could do me a fav and the above code put it into 1 function ? with 2 parametres 1 for date and the other for dj name so be like

    CheckForDj($date,$djname);

    so that input would first check the input of the textfield (wich will be the date) if the format is in valid format, DD/MM/YY, if it isnt then echo error sumthing like 'invalid date format' if the format is correct then it will go on to check if the date is valid if the date is invalid then echo error 'invalid date' if both of them pass then it will check against a text file the date entered and the dj name for example CheckForDj(this bit will be requested from the textfield the date,'Peter'); so if the date EXISTS in the text file then echo 'not available' if it is NOT in the text file then echo available, i have done that bit but i would require it in 1 function rather than 3 with the params above, if you do it as described i will give u $10 thru paypal (if u got) as a little thank you this shouldnt be much work at all considering the code is almost complete a few things need changeing is the date format, i would like it to be DD/MM/YY rather than the current DD-MM-YY, also for example if there are 3 djs and all three are avilable should say something like dj1, dj2 and dj3 are available if there is 4 it would say dj1, dj1, dj3 and dj3 are available however is there is only 2 it will say dj1 and dj2 are available and in the text file it will say DD/MM/YY dj1, dj2 so them 2 dj's are not avilable but the 3rd is,

    look forward to your reply hope you can help, thaks so much
    Last edited by Locky; 03-24-2007 at 07:33 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •