Log in

View Full Version : Availability Checker Script



Locky
03-21-2007, 10:44 PM
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

boxxertrumps
03-21-2007, 11:09 PM
<?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.";}
?>

Locky
03-22-2007, 12:59 PM
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

boxxertrumps
03-22-2007, 01:52 PM
Ajax. Im bad with javascript, so you'll have to ask someone else.

thetestingsite
03-22-2007, 02:05 PM
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):


<body>
<?php

if (isset($_REQUEST['textfield']) && !empty($_REQUEST['textfield'])) {
echo $_REQUEST['textfield'];
}
?>
</body>


Hope this helps.

Locky
03-22-2007, 02:30 PM
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):


<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

Locky
03-22-2007, 02:45 PM
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 :D thank you so much

thetestingsite
03-23-2007, 11:51 PM
Sorry, did not see the edit until just now. Do you mean something like this:

(Example, not real code snippet)


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.

Locky
03-24-2007, 11:53 AM
Sorry, did not see the edit until just now. Do you mean something like this:

(Example, not real code snippet)


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.";}
?>

Locky
03-24-2007, 07:25 PM
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

John A
06-21-2007, 11:20 AM
Locky, did you ever finish this script and get it working?

I've got a use for it (Wedding Photographer) and have some funds burning a hole in my Paypal account if you'd like to share...?

illuminiphoto
12-13-2008, 12:32 AM
Hi, I have the same issue as locky but I am confused as to how to string the code abaove to get working.

I would like a web page to display a text box where the user types in a date (dd/mm/yy) and submit button. The code then needs to search a text file for the date inputted and if in the text file the same web page displays 'congratulation' , if no date in text file the user inputted then displays 'sorry'.

Please could anybody help me with such a script?

Thanks in advance.