foreach insert error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello All,

I have spent the entire day trying to get my calendar app to function
correctly ---  I have no problem with the actual functioning of the
calendar. What is giving me trouble is for each calendar day the user has
the option to check a checkbox requesting the day off and additionally the
user must select a weighting for the request i.e. 1-31 with 1 being 1st
choice and 31 being their least desirable request. The request is then
insered into a mysql database.

I am relativly new to PHP so I may well be on the complete wrong track here.
so far I have tried imploding the array & posting an associative array.

Form Script:

<div class="workspace">
<?php
if(isset($_POST['submit'])){

    $userID = mysql_real_escape_string(trim($userID));
    $year = mysql_real_escape_string(trim($_GET['year']));
    $month = mysql_real_escape_string(trim($_GET['mon']));
    $dayoff = $_POST['dayoff'];
    $weighting = mysql_real_escape_string(trim($_POST['weight']));
    var_dump($dayoff);

        foreach ($dayoff as
$day){                                                         //come back
to this when figured out that inserting day works to inser wieghting

        $sql = "INSERT INTO dayoff (userID, month, year, day) VALUES
('$userID', '$year', '$month', '$day')";

        $q = mysql_query($sql)
        or die ('error making request');
        }


 }
?>
<div class="form">
<form name="form" method="post" action="<?php $_SERVER['PHP_SELF'] ; ?>">
<h2>Request Day Off</h2><br /><br />
<?php include '../includes/dayoffcalendar.php' ; ?>

<br /><br /><br />
<button type="submit" name="submit" value="Submit"
class="button">Submit</button>
<button type="reset" class="button">Reset</button>
</form>

Calendar Script:


for($i = 1; $i <= $last['mday']; $i++){
   if($i == $today['mday'] && $first['mon'] == $today['mon'] &&
$first['year'] == $today['year']){
      $style = 'today';
   }
   else{
      $style = 'day';
   }
   $filename="$1.['month'].['year']";
   echo '  <div class="' . $style . '">' . $i . '<br /><br />' ; // creates
comment box for points and check box for request day off
   echo '  <label><small>Point Weighting: </small></label><input type="text"
name="weight$i[]" size ="3" maxlength="3" /><Br /><br /> ';
   echo '  <label><small>Check Day Off: </small></label><input type
="checkbox" name="dayoff[]" value="\". $i . \"" /><br /> ';
   echo '  </div>' . "\n";

   }

I appreciate any advice that you may have. Thank you very much in advance,
my head hurts and I've googled for a few hours with no joy.

Thanks

Haig

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux