Hey everybody.
I'm verrynew to PHP and MYSQL and have been working on a form that
when it is submitted stores the information into a mysql database.
The main problem is that i'm trying to finish up my script for almost
a week now and I still cant get it right.
here is the code
<?php
include ("ES_includes/appconst.inc.php") ;
// Ceck of begin datum juist is
if (!checkdate ($_POST['maand_van'],$_POST['dag_van'],$_POST['jaar_van'])){
echo "De begin datum die u hebt opgegeven is ontjuist <b>"
..$_POST['dag_van']. "/" .$_POST['maand_van']. "/" .$_POST['jaar_van'].
"</b>.<br>";
}
else
{
//check of begin datum reeds in het database staat
$datum= $_POST['jaar_van']."-".$_POST['maand_van']."-".$_POST['dag_van'];
$db = mysql_connect("$dbHost", "$dbUser","$dbPwd");
mysql_select_db($dbName,$db);
$sql_check = "SELECT * FROM verlof WHERE
gebruikersID='$_POST['gebruikersID']' AND datum='$datum'";
$check = mysql_query($sql_check,$db);
if (mysql_num_rows($check) != 0){
echo "Deze datums staan reeds in het databse op uw naam.\n";
}
else
{
$sql = "INSERT INTO verlof (gebruikersID, datum, voormiddag,
namiddag, opm_aanvrager) VALUES
('$_POST['gebruikersID']','$datum','$_POST['voormiddag']','$_POST['namiddag']','$_POST['opm_aanvrager']')";
$result = mysql_query($sql);
echo "Uw verlof aanvraag is aangevraagd.\n";
}
}
echo "<br><input type=button value=\"Terug\"
onClick=\"history.go(-1)\"><br>";
$datum_van= $_POST['dag_van']."/".$_POST['maand_van']."/".$_POST['jaar_van'];
$datum_tot= $_POST['dag_tot']."/".$_POST['maand_tot']."/".$_POST['jaar_tot'];
$day1="Monday";
$day2="Tuesday";
$day3="Wednesday";
$day4="Thursday";
$day5="Friday";
$mydate=$datum_van;
$newsplit = explode("/", $mydate);
$dat1=mktime(0,0,0,$newsplit[1],$newsplit[0],$newsplit[2]);
$mydate=$datum_tot;
$newsplit = explode("/", $mydate);
$dat2=mktime(0,0,0,$newsplit[1],$newsplit[0],$newsplit[2]);
$datc=$dat1;
while ($datc<=$dat2){
$datw=date("d/m/Y",$datc);
$jour=date ("l", $datc);
if ($day1==$jour || $day2==$jour || $day3==$jour || $day4==$jour
|| $day5==$jour){
print (date("Y/m/d",$datc)."<br>");
} $datc=$datc + 86400;
}
?>
Now what does it have to do..
When the form gets submitted it must check it datum_van is correct
if (!checkdate ($_POST['maand_van'],$_POST['dag_van'],$_POST['jaar_van'])){
and here is my first problem.
It also has to check if datum_tot is valid so there has to be a new
if (!checkdate ($_POST['maand_van'],$_POST['dag_van'],$_POST['jaar_van'])){
but this time with the values of dag_tot, maand_tot, jaar_tot
than it should get all the weekdays (from mon. till vri.) between
those two dates and this is the script i use for it
$datum_van= $_POST['dag_van']."/".$_POST['maand_van']."/".$_POST['jaar_van'];
$datum_tot= $_POST['dag_tot']."/".$_POST['maand_tot']."/".$_POST['jaar_tot'];
$day1="Monday";
$day2="Tuesday";
$day3="Wednesday";
$day4="Thursday";
$day5="Friday";
$mydate=$datum_van;
$newsplit = explode("/", $mydate);
$dat1=mktime(0,0,0,$newsplit[1],$newsplit[0],$newsplit[2]);
$mydate=$datum_tot;
$newsplit = explode("/", $mydate);
$dat2=mktime(0,0,0,$newsplit[1],$newsplit[0],$newsplit[2]);
$datc=$dat1;
while ($datc<=$dat2){
$datw=date("d/m/Y",$datc);
$jour=date ("l", $datc);
if ($day1==$jour || $day2==$jour || $day3==$jour || $day4==$jour
|| $day5==$jour){
print (date("Y/m/d",$datc)."<br>");
} $datc=$datc + 86400;
}
now here is the second problem.
in my database i have one table called datum
now for every weekday between these two dates the script must create a
record
so that when i submit my form with the following dates
13/01/2003
18/01/2003
and I have selected "namiddag or voormiddag" in my form
I would find in my datase the following records
__________________________________________________ _________________
| gebruikersID | datum | voormiddag | namiddag |opm_aanvrager|
-------------------------------------------------------------------
| Username |13/01/2003 | 1 |or| 1 | some text |
| Username |14/01/2003 | 0 |0 | some text |
| Username |15/01/2003 | 0 |0 | some text |
| Username |16/01/2003 | 0 |0 | some text |
| Username |17/01/2003 | 0 |0 | some text |
-------------------------------------------------------------------
the 18th will be left out because it is a saterday.
I hope some of the experts here can help me out because I'm totaly
lost and realy need this script asap many thanks in advanced
Tiernan.
ps. sorry for my english :)