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

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

paddy086Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rgranlundCommented:
Download this. It works great!
http://jqueryui.com/datepicker/
0
paddy086Author Commented:
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
Ray PaseurCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ray PaseurCommented:
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
paddy086Author Commented:
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
paddy086Author Commented:
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
Ray PaseurCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paddy086Author Commented:
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
Ray PaseurCommented:
Hmm... This is probably where var_dump() can give you the information you need!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.