Solved

Existing HTML PHP input form----Needs Date Picker Added

Posted on 2014-10-22
9
719 Views
Last Modified: 2014-10-23
Hello Experts

So what I have is an Existing Html Php Input form that looks like picture attached. I know the php is not up to date but the system is accessible from the internet and we will be getting a company to redo the whole PHP and SQL in a year or so.

I need a Date picker added to the form so the user can select a date from a calendar that will then go into my SQL database.

On line 55 of absent1.php when the user selects a name from the Absent Teacher that name is populated on all 9 input forms I will also need the date picker to do this as well if possible

Thanks experts for any help give it is much appreciated

Attached are
picture of html form
Html form-absent1.php
Php code- absent1.1.php
Php code 2- php.php

 picture
absent1.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Absent Teacher 1 Week.1 Monday</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../styles.css" />
<script type="text/javascript">
function syncSelects(objSel) {
	for(var i=2; i<=9; ++i) {
		objSel.form.elements['sickteacher['+i+']'].selectedIndex = objSel.selectedIndex;
	}
}
</script> 
</head>
<?php 

    // First we execute our common code to connection to the database and start the session
     require("../../common.php"); 
     
    // At the top of the page we check to see whether the user is logged in or not
     if(empty($_SESSION['user'])) 
    { 
        // If they are not, we redirect them to the login page. 
        header("Location: ../../login.php"); 
         
        // Remember that this die statement is absolutely critical.  Without it,
         // people can view your members-only content without logging in. 
        die("Redirecting to ../../login.php"); 
    } 
     
    // Everything below this point in the file is secured by the login system 
     
    // We can display the user's username to them by reading it from the session array.  Remember that because
     // a username is user submitted content we must use htmlentities on it before displaying it to the user.  The
     // fact that we retrieved it from a database and not directly from the user does not matter.
 ?>
<body>
<div id="container">
<div id="header"> <img name="Logo" src="../../images/logo.png" width="233" height="76" alt=""></div>
<div id="content">
      <p><caption><h2>Absent Teacher 1 Week.1 Monday</h2></caption>
<form action="absent1.1.php" method="POST"> 
<?php include('../../php.php'); ?>


<?php



for($i=1;$i<=9; ++$i): ?>
<pre> 
<fieldset>
<legend>Absent Teacher 1 </legend>
Period: <input type="text" name="period[<?php echo $i; ?>]" size="1" readonly value="<?php echo $i; ?>" ><br> 
Absent Teacher:  <select name="sickteacher[<?php echo $i ?>]"<?php echo ($i==1)?' onchange="syncSelects(this);"':''; ?>><?php echo $options ?></select><br>
Subject:  <select name="subject[<?php echo $i ?>]"><?php echo $subject_options ?></select><br>
Class:  <select name="class[<?php echo $i ?>]"><?php echo $class_options ?></select><br>
Room:  <select name="room[<?php echo $i ?>]"><?php echo $room_options ?></select><br>
Cover Teacher: <select name="coverteacher[<?php echo $i ?>]"><?php echo $options ?></select>
</fieldset>
</pre> 
<?php endfor; ?>

<input type="submit" value="Add Teacher 1 Cover"> 
<input type="reset" value="Reset"> 
    <p>&nbsp;</p>
    <p>&nbsp;</p>
</form> 

</body>
</html></p>
      <p>
  </div>
  </div>
<div id="navigation">
    <p><strong>Navigation Here</strong></p>
    <ul>
<li><a href="http://localhost/w1/mon/w1mon.php">Week 1 Monday Picker</a></li>
<hr>
<li><a href="http://localhost/../../administrator.php">Administrator Page </a></li>
<hr>
      <li><a href="http://localhost/../../logout.php">Logout</a></li>
      <hr>
    </ul>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </div>

</body> 
  <div id="wrapper"></div>
  <div id="footer">
    <p>Absent Tables</p>
  </div>
</div>
</body>
</html>

Open in new window


absent1.1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="03;URL='http://localhost/w1/mon/absent2.php'" />

</head> 
<body> 

<?php 

// Read values from form using $_POST (safest) 

$period=$_POST["period"]; 
$sickteacher=$_POST["sickteacher"];
$subject=$_POST["subject"];
$class=$_POST["class"];
$room=$_POST["room"]; 
$coverteachere=$_POST["coverteacher"]; 

// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","****","****"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

$getUser_sql = 'SELECT * FROM teacher ORDER BY name';
$getUser =mysql_query($getUser_sql);
//connect to db first
//...

//then iterate over posted info
foreach($_POST['period'] as $i =>$v)
{
   $period=mysql_real_escape_string($_POST['period'][$i]);
   $sickteacher=mysql_real_escape_string($_POST['sickteacher'][$i]);
   $subject=mysql_real_escape_string($_POST['subject'][$i]);
   $class=mysql_real_escape_string($_POST['class'][$i]);
   $room=mysql_real_escape_string($_POST['room'][$i]);
   $coverteacher=mysql_real_escape_string($_POST['coverteacher'][$i]);

  $sql="INSERT INTO w1monsick1 (period,sickteacher,subject,class,room,coverteacher) values ($period,'$sickteacher','$subject','$class','$room','$coverteacher')";

  mysql_query($sql) or die(mysql_error());
}
?>  



</body> 
</html>

Open in new window


php.php
<?php 

// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","******","********"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

//connect to db first
$options = '';
$teachers = mysql_query('SELECT * FROM teacher ORDER BY name ASC');
while($teacher = mysql_fetch_array($teachers)) {
     $options .= sprintf('<option value="%s">%s</option>', $teacher['name'], $teacher['name']);	 
}
$class_options = '';
$classes = mysql_query('SELECT * FROM class ORDER BY id ASC');
while($class = mysql_fetch_array($classes)) {
     $class_options .= sprintf("<option value='%s'>%s</option>", $class['name'], $class['name']);
}
$room_options = '';
$rooms = mysql_query('SELECT * FROM room ORDER BY number ASC');
while($room = mysql_fetch_array($rooms)) {
     $room_options .= sprintf("<option value='%s'>%s</option>", $room['number'], $room['number']);
}
$subject_options = '';
$subjects = mysql_query('SELECT * FROM subject ORDER BY name ASC');
while($subject = mysql_fetch_array($subjects)) {
     $subject_options .= sprintf("<option value='%s'>%s</option>", $subject['name'], $subject['name']);
}
?>

Open in new window

0
Comment
Question by:paddy086
  • 4
  • 4
9 Comments
 
LVL 7

Assisted Solution

by:rgranlund
rgranlund earned 250 total points
ID: 40397538
Download this. It works great!
http://jqueryui.com/datepicker/
0
 

Author Comment

by:paddy086
ID: 40397594
Hi rgranlund

Yes I was looking at the Jquery Datepicker but I could not get it to work with my html and php form.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40397611
could not get it to work...
What errors did you get?  Did you use the Chrome Dev Tools to check the installation?  Please show us what you've tried, thanks.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40397644
See also this example.
http://iconoun.com/demo/temp_paddy086.php

You can learn more about how to handle date/time values in PHP here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

<?php // demo/temp_paddy086.php
error_reporting(E_ALL);

// IF THE DATE WAS SUBMITTED, USE IT IN PHP
if (!empty($_POST['chosen_date']))
    echo PHP_EOL . date('c', strtotime($_POST['chosen_date']));

// CREATE THE HTML USING HEREDOC NOTATION (ADAPTED FROM http://jqueryui.com/datepicker/)
$htm = <<<EOD
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
    $("#datepicker").datepicker();
});
</script>
</head>
<body>
<form method="post">
<p>Date: <input name="chosen_date" type="text" id="datepicker" /></p>
<input type="submit" />
</form>
</body>
</html>
EOD;

echo $htm;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:paddy086
ID: 40397733
Hi Ray

I just added the DatePicker Script and the DatePicker input to my form and edited the Absent1.1.php
as follows

absent1.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Absent Teacher 1 Week.1 Monday</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../styles.css" />
<script type="text/javascript">
function syncSelects(objSel) {
	for(var i=2; i<=9; ++i) {
		objSel.form.elements['sickteacher['+i+']'].selectedIndex = objSel.selectedIndex;
	}
}
</script> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>

  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

  <link rel="stylesheet" href="/resources/demos/style.css">

  <script>

  $(function() {

    $( "#datepicker" ).datepicker();

  });

  </script>


</head>
<?php 

    // First we execute our common code to connection to the database and start the session
     require("../../common.php"); 
     
    // At the top of the page we check to see whether the user is logged in or not
     if(empty($_SESSION['user'])) 
    { 
        // If they are not, we redirect them to the login page. 
        header("Location: ../../login.php"); 
         
        // Remember that this die statement is absolutely critical.  Without it,
         // people can view your members-only content without logging in. 
        die("Redirecting to ../../login.php"); 
    } 
     
    // Everything below this point in the file is secured by the login system 
     
    // We can display the user's username to them by reading it from the session array.  Remember that because
     // a username is user submitted content we must use htmlentities on it before displaying it to the user.  The
     // fact that we retrieved it from a database and not directly from the user does not matter.
 ?>
<body>
<div id="container">
<div id="header"> <img name="Logo" src="../../images/logo.png" width="233" height="76" alt=""></div>
<div id="content">
      <p><caption><h2>Absent Teacher 1 Week.1 Monday</h2></caption>
<form action="absent1.1.php" method="POST"> 
<?php include('../../php.php'); ?>


<?php



for($i=1;$i<=9; ++$i): ?>
<pre> 
<fieldset>
<legend>Absent Teacher 1 </legend>
Period: <input type="text" name="period[<?php echo $i; ?>]" size="1" readonly value="<?php echo $i; ?>" ><br>
Date: <input type="text" name="datepicker" id="datepicker"[<?php echo $i ?>]><br>
Absent Teacher:  <select name="sickteacher[<?php echo $i ?>]"<?php echo ($i==1)?' onchange="syncSelects(this);"':''; ?>><?php echo $options ?></select><br>
Subject:  <select name="subject[<?php echo $i ?>]"><?php echo $subject_options ?></select><br>
Class:  <select name="class[<?php echo $i ?>]"><?php echo $class_options ?></select><br>
Room:  <select name="room[<?php echo $i ?>]"><?php echo $room_options ?></select><br>
Cover Teacher: <select name="coverteacher[<?php echo $i ?>]"><?php echo $options ?></select>
</fieldset>
</pre> 
<?php endfor; ?>

<input type="submit" value="Add Teacher 1 Cover"> 
<input type="reset" value="Reset"> 
    <p>&nbsp;</p>
    <p>&nbsp;</p>
</form> 

</body>
</html></p>
      <p>
  </div>
  </div>
<div id="navigation">
    <p><strong>Navigation Here</strong></p>
    <ul>
<li><a href="http://localhost/w1/mon/w1mon.php">Week 1 Monday Picker</a></li>
<hr>
<li><a href="http://localhost/../../administrator.php">Administrator Page </a></li>
<hr>
      <li><a href="http://localhost/../../logout.php">Logout</a></li>
      <hr>
    </ul>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </div>

</body> 
  <div id="wrapper"></div>
  <div id="footer">
    <p>Absent Tables</p>
  </div>
</div>
</body>
</html>

Open in new window


absent1.1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="03;URL='http://localhost/w1/mon/absent2.php'" />

</head> 
<body> 

<?php 

// Read values from form using $_POST (safest) 

$period=$_POST["period"]; 
$datepicker=$_POST["datepicker"];
$sickteacher=$_POST["sickteacher"];
$subject=$_POST["subject"];
$class=$_POST["class"];
$room=$_POST["room"]; 
$coverteachere=$_POST["coverteacher"]; 

// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","*****","I************"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

$getUser_sql = 'SELECT * FROM teacher ORDER BY name';
$getUser =mysql_query($getUser_sql);
//connect to db first
//...

//then iterate over posted info
foreach($_POST['period'] as $i =>$v)
{
   $period=mysql_real_escape_string($_POST['period'][$i]); 
   $datepicker=mysql_real_escape_string($_POST['datepicker'][$i]);
   $sickteacher=mysql_real_escape_string($_POST['sickteacher'][$i]);
   $subject=mysql_real_escape_string($_POST['subject'][$i]);
   $class=mysql_real_escape_string($_POST['class'][$i]);
   $room=mysql_real_escape_string($_POST['room'][$i]);
   $coverteacher=mysql_real_escape_string($_POST['coverteacher'][$i]);

  $sql="INSERT INTO w1monsick1 (period,/datepicker,sickteacher,subject,class,room,coverteacher) values ($period,'$sickteacher','$subject','$class','$room','$coverteacher')";

  mysql_query($sql) or die(mysql_error());
}
?>  



</body> 
</html>

Open in new window


I get an error when I run it
Notice: Uninitialized string offset: 1 in C:xampp\absent1.1php on line 45
0
 

Author Comment

by:paddy086
ID: 40397783
Sorry Line 52 had a error
 
$sql="INSERT INTO w1monsick1 (period,/datepicker,sickteacher,subject,class,room,coverteacher) values ($period,'$sickteacher','$subject','$class','$room','$coverteacher')";

Should have been
 $sql="INSERT INTO w1monsick1 (period,datepicker,sickteacher,subject,class,room,coverteacher) values ($period,'$sickteacher','$subject','$class','$room','$coverteacher')";

but now I am getting this
Notice: Uninitialized string offset: 1 in C:xampp\absent1.1php on line 45
Column count doesn't match value count at row 1
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 40398088
Yes, the column count here appears to be 7 and the values count appears to be 6.  You may also want to learn about var_dump() which can give you a way to see exactly what is in the $_POST array.
http://php.net/manual/en/function.var-dump.php

$sql
=
"
INSERT INTO w1monsick1 
( period
, datepicker
, sickteacher
, subject
, class
, room
, coverteacher
) 
VALUES
( $period
/* DATEPICKER VALUE APPEARS TO BE MISSING HERE */
, '$sickteacher'
, '$subject'
, '$class'
, '$room'
, '$coverteacher'
)
"
;

Open in new window

0
 

Author Comment

by:paddy086
ID: 40398098
Hi
I got it to work just now.
 so my last issue is have the date populate over the 8 input forms the same way Absent Teacher dose

absent1.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Absent Teacher 1 Week.1 Monday</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../styles.css" />
<script type="text/javascript">
function syncSelects(objSel) {
	for(var i=2; i<=9; ++i) {
		objSel.form.elements['sickteacher['+i+']'].selectedIndex = objSel.selectedIndex;
	}
}
</script> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>

  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

  <link rel="stylesheet" href="/resources/demos/style.css">

  <script>

  $(function() {

    $( "#datepicker" ).datepicker();

  });

  </script>


</head>
<?php 

    // First we execute our common code to connection to the database and start the session
     require("../../common.php"); 
     
    // At the top of the page we check to see whether the user is logged in or not
     if(empty($_SESSION['user'])) 
    { 
        // If they are not, we redirect them to the login page. 
        header("Location: ../../login.php"); 
         
        // Remember that this die statement is absolutely critical.  Without it,
         // people can view your members-only content without logging in. 
        die("Redirecting to ../../login.php"); 
    } 
     
    // Everything below this point in the file is secured by the login system 
     
    // We can display the user's username to them by reading it from the session array.  Remember that because
     // a username is user submitted content we must use htmlentities on it before displaying it to the user.  The
     // fact that we retrieved it from a database and not directly from the user does not matter.
 ?>
<body>
<div id="container">
<div id="header"> <img name="Logo" src="../../images/logo.png" width="233" height="76" alt=""></div>
<div id="content">
      <p><caption><h2>Absent Teacher 1 Week.1 Monday</h2></caption>
<form action="absent1.1.php" method="POST"> 
<?php include('../../php.php'); ?>


<?php



for($i=1;$i<=9; ++$i): ?>
<pre> 
<fieldset>
<legend>Absent Teacher 1 </legend>
Period: <input type="text" name="period[<?php echo $i; ?>]" size="1" readonly value="<?php echo $i; ?>" ><br>
Date: <input type="text" id="datepicker" name="datepicker[<?php echo $i ?>]"><br>
Absent Teacher: <select name="sickteacher[<?php echo $i ?>]"<?php echo ($i==1)?' onchange="syncSelects(this);"':''; ?>><?php echo $options ?></select><br>
Subject:  <select name="subject[<?php echo $i ?>]"><?php echo $subject_options ?></select><br>
Class:  <select name="class[<?php echo $i ?>]"><?php echo $class_options ?></select><br>
Room:  <select name="room[<?php echo $i ?>]"><?php echo $room_options ?></select><br>
Cover Teacher: <select name="coverteacher[<?php echo $i ?>]"><?php echo $options ?></select>
</fieldset>
</pre> 
<?php endfor; ?>

<input type="submit" value="Add Teacher 1 Cover"> 
<input type="reset" value="Reset"> 
    <p>&nbsp;</p>
    <p>&nbsp;</p>
</form> 

</body>
</html></p>
      <p>
  </div>
  </div>
<div id="navigation">
    <p><strong>Navigation Here</strong></p>
    <ul>
<li><a href="http://localhost/w1/mon/w1mon.php">Week 1 Monday Picker</a></li>
<hr>
<li><a href="http://localhost/../../administrator.php">Administrator Page </a></li>
<hr>
      <li><a href="http://localhost/../../logout.php">Logout</a></li>
      <hr>
    </ul>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </div>

</body> 
  <div id="wrapper"></div>
  <div id="footer">
    <p>Absent Tables </p>
  </div>
</div>
</body>
</html>

Open in new window


absent1.1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="03;URL='http://localhost/w1/mon/absent2.php'" />

</head> 
<body> 

<?php 

// Read values from form using $_POST (safest) 

$period=$_POST["period"]; 
$datepicker=$_POST["datepicker"];
$sickteacher=$_POST["sickteacher"];
$subject=$_POST["subject"];
$class=$_POST["class"];
$room=$_POST["room"]; 
$coverteachere=$_POST["coverteacher"]; 

// Connect to server 
// Replace username and password by your details  

$db = @mysql_connect("localhost","root","iqonr301"); 
if (!$db) 
{ 
        do_error("Could not connect to the server"); 
} 


// Connect to the database 
// Note that your database will be called username 

@mysql_select_db("test",$db)or do_error("Could not connect to the database"); 

$getUser_sql = 'SELECT * FROM teacher ORDER BY name';
$getUser =mysql_query($getUser_sql);
//connect to db first
//...

//then iterate over posted info
foreach($_POST['period'] as $i =>$v)
{
   $period=mysql_real_escape_string($_POST['period'][$i]); 
   $datepicker=mysql_real_escape_string($_POST['datepicker'][$i]);
   $sickteacher=mysql_real_escape_string($_POST['sickteacher'][$i]);
   $subject=mysql_real_escape_string($_POST['subject'][$i]);
   $class=mysql_real_escape_string($_POST['class'][$i]);
   $room=mysql_real_escape_string($_POST['room'][$i]);
   $coverteacher=mysql_real_escape_string($_POST['coverteacher'][$i]);

  $sql="INSERT INTO w1monsick1 (period,datepicker,sickteacher,subject,class,room,coverteacher) values ($period,'$datepicker','$sickteacher','$subject','$class','$room','$coverteacher')";

  mysql_query($sql) or die(mysql_error());
}
?>  



</body> 
</html>

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40398333
Hmm... This is probably where var_dump() can give you the information you need!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now