By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Need help pls... cant fiugre out the solution....

P: n/a
Hey everybody.
I'm verry new 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..
it should get all the weekdays (from mon. till vri.) between
those datum_van and datum_tot 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 :)
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

On 19-Aug-2003, mi*************@bluestripes.be (Tiernan) wrote:
I'm verry new 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");
Every database call should have error checking. Add ' or die('connect failed
because '.mysql_error()) ' to the above (before the ;). Like:
$db = mysql_connect("$dbHost", "$dbUser","$dbPwd") or die('connect failed
because '.mysql_error());
mysql_select_db($dbName,$db);
add error checking
$sql_check = "SELECT * FROM verlof WHERE
gebruikersID='$_POST['gebruikersID']' AND datum='$datum'";
When referencing an array IN A STRING you do NOT enclose the array index in
quotes. Change '$_POST['gebruikersID']' to '$_POST[gebruikersID]' in the
line above.
$check = mysql_query($sql_check,$db);
add error checking

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']')";
remove the quotes around the array indexes
$result = mysql_query($sql);
add error checking
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;
}
The above while loop doesn't seem to have any syntax errors but it is very
hard to read, please use proper indentation and avoid putting more than one
statement on a line. It should look like this:
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;
}


?>


Fix the syntax errors first, then work on the logic errors. While you are at
it, fix the indentation and put every statement on a separate line.

If you post here again, please ask a specific question. Tell us specifically
what error message you are getting and on what line or if the output is
wrong what is wrong with it, give an example.
--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #2

P: n/a
Thx Tom Thackrey, with your information you got me back on track...
i have added the error checks like your said... had them there before
but left them out till the end... so now I have edited my script and
came up with the next result.

<?php
include ("ES_includes/appconst.inc.php") ;

// check of begin datum juist is

if (!checkdate ($_POST['maand_van'],$_POST['dag_van'],$_POST['jaar_van'])){
echo "De begin datum van uw aanvraag is geen geldige datum <b>"
..$_POST['dag_van']. "/" .$_POST['maand_van']. "/"
..$_POST['jaar_van']."</b>.<br>";
}
elseif (!checkdate ($_POST['maand_tot'],$_POST['dag_tot'],$_POST['jaar_tot'])){
echo "De eind datum van uw aanvraag is geen geldige datum <b>"
..$_POST['dag_tot']. "/" .$_POST['maand_tot']. "/" .$_POST['jaar_tot'].
"</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")
or die('Connecting to database failed.');

mysql_select_db($dbName,$db)
or die('Unable to select database.');

$sql_check = "SELECT * FROM verlof WHERE
gebruikersID='$_POST[gebruikersID]' AND datum='$datum'";
$check = mysql_query($sql_check,$db)
or die('Unable to query database.');

if (mysql_num_rows($check) != 0){
echo "Deze datums staan reeds in het databse op uw naam.\n";
}
else
{

//Filter datums tussen begi nen eind datum
$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>");
}

$sql = "INSERT INTO verlof (gebruikersID, datum, voormiddag,
namiddag, opm_aanvrager) VALUES
('".$_POST['gebruikersID']."','".date("Y-m-d",$datc)."','".$_POST['voormiddag']."','".$_POST['namiddag']."','".$_POST['opm_aanvrager']."')";
$result = mysql_query($sql)
or die('Unable to query database');
echo "Uw verlof aanvraag is aangevraagd.\n";
$datc=$datc + 86400;
}
}}

echo "<br><input type=button value=\"Terug\"
onClick=\"history.go(-1)\"><br>";
?>

Now by editing this script I finaly got the solution on how to create
a record with the "gebruikersID" and all the rest that was needed for
every date between the starting date and the end date... so that
problem seems to be solved.

But the thing it doesn't do is leave out the dates that are in a
weekend (like saterday and sunday) those to days should be left out...

So i hope any of you can help me solve this problem because I'm
getting verry confused and angry on my computer (:p)

Anyway Tom Thackrey thanks again for your information.
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.