Link to home
Create AccountLog in
Avatar of paddy086
paddy086Flag for Ireland

asked on

Input forms HTML/PHP select one person name populate the other 9 input forms with name

Hello
Well first I have 2 pictures first is a absent1 this page shows the how the user inputs the info into database.
Second picture is tables this shows the person who is out sick and who is covering up to 9 periods a day.
My issue is on the input page absent1.php. On this page over the 9 periods the same person is going to be out sick so is there a way that when you select the person from the dropdown menu in the first absent teacher box that it will populate the rest of the following boxes for the 9 periods


absent input form fieldset

Line 36 is a link to php.php witch gadders the info from a database and displays it in dropdown menus
Line 43 to 58 is the lines were the 9 period input forms are generated. So what I need is if I select say paddy as being out absent in period one that period 2 to 9 will auto populate with the same name. So I need to change them from dropdown menu to ???????


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Absent Teacher 1</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="styles.css" />
</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 </h2></caption>
<form action="http://localhost/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 $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/absent2.php">Absent Teacher 2</a></li>
<li><a href="http://localhost/absent3.php">Absent Teacher 3</a></li>
<li><a href="http://localhost/absent4.php">Absent Teacher 4</a></li>
<li><a href="http://localhost/absent5.php">Absent Teacher 5</a></li>
<li><a href="http://localhost/absent6.php">Absent Teacher 6</a></li>
<li><a href="http://localhost/absent7.php">Absent Teacher 7</a></li>
<li><a href="http://localhost/absent8.php">Absent Teacher 8</a></li>
<li><a href="http://localhost/absent9.php">Absent Teacher 9</a></li>
<li><a href="http://localhost/absent10.php">Absent Teacher 10</a></li>
<li><a href="http://localhost/absent11.php">Absent Teacher 11</a></li>
<li><a href="http://localhost/absent12.php">Absent Teacher 12</a></li>
<li><a href="http://localhost/absent13.php">Absent Teacher 13</a></li>
<li><a href="http://localhost/absent14.php">Absent Teacher 14</a></li>
<li><a href="http://localhost/absent15.php">Absent Teacher 15</a></li>
<li><a href="http://localhost/absent16.php">Absent Teacher 16</a></li>
<li><a href="http://localhost/absent17.php">Absent Teacher 17</a></li>
<li><a href="http://localhost/absent18.php">Absent Teacher 18</a></li>
<li><a href="http://localhost/absent19.php">Absent Teacher 19</a></li>
<li><a href="http://localhost/absent20.php">Absent Teacher 20</a></li>
<li><a href="http://localhost/tables.php">Absent Tables Display</a></li>
<li><a href="http://localhost/empty.php">Empty Absent Tables</a></li>
<li><a href="http://localhost/administrator.php">Administrator Page </a></li>
      <li><a href="http://localhost/logout.php">Logout</a></li>
    </ul>
    <p>&nbsp;</p>
    
    </div>

</body> 
  <div id="wrapper"></div>
  <div id="footer">
    <p>my site</p>
  </div>
</div>
</body>
</html>

Open in new window


Absent1.1php is the script that populates the database from the input from

<!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/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("myhost","myroot","mypass"); 
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 sick1 (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 script just in case you need it. this script get the names and ect for the dropdown menus

<?php 

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

$db = @mysql_connect("myhost","myroot","mypass"); 
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');
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');
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

Absent-teacher-1.png
absent-table.png
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of paddy086

ASKER

Thank you robert_schutt that worked