使用两个表(班级老师,学生)和列名出勤和评论中的一些列将值插入表格出勤

时间:2014-01-02 07:10:20

标签: php mysql

嗨,我有两张桌子名字班老师和学生。我想将这些表中的一些列值插入到我的表出席状态以及列名称出勤标记,comments。但它显示所有变量的未定义索引。指导我如何将这些值存储在考勤表中。 在此先感谢。

  <html>
  <head><title>class grade1</title>
  <?php

   $mysql_hostname = "localhost";
   $mysql_user = "root";
   $mysql_password = ""; 
   $mysql_database = "my_attendance";
   $prefix = "";

   $db = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
   or die("Could not  connect database");
    //echo "hurray!!!connection successful";
    mysql_select_db($mysql_database, $db) or die("Could not select database");


   ?>
   </head>
   <body>
   <h1 align="center">Grade1 Attendance</h1>

   <table align="center" border="1" width="250" height="100" cellspacing="1"
   cellpadding="1">
   <th>Classid</th>
   <th>StudentId</th>
   <th>Dateid</th>
   <th>Flag</th>
   <th>Teacher Id</th>
   <th>Location Id</th>
   <th>Comments</th>

   <?php
   echo "<form action=insertattend.php method=POST >";
   echo "<tr>";
   ?>
   <?php
     $query = ("SELECT classid,fname from student_master WHERE classid='grade1' ") ;
        $result = mysql_query($query,$db) or die(mysql_error($db));

        while ($row = mysql_fetch_array($result))  
    {

    //echo "<td>" . "<input type=text name=ids value=" .$row['id']." </td>";
    echo "<td>" . "<input type=name name=classid value=" .$row['classid']." </td>";
    echo "<td>" . "<input type=name=fname value=" .$row['fname']." </td>";
    }
    ?>  
<?php   echo "<td>" . "<input type=date name=date value=" .$row['dateid']." </td>";
    echo "<td>" . "<input type=radio name=attend value='present'" . "</td>"; ?>   P
 <?php echo "<input type=radio name=attend value='absent' ". "</td>";
     ?> A
   <?php


    $query = "SELECT teacherid FROM teacher_link WHERE classid='grade1' ";  

    $result2 = mysql_query($query, $db) or die(mysql_error($db));  

    while ($row = mysql_fetch_array($result2))  
    {  
    echo "<td>" . "<input type=number name=teacherid value=" .$row['teacherid']
    ." </td>";
    }
    ?>
    <?php

    $query = "SELECT locid FROM class_master WHERE classid='grade1' ";  

    $result3 = mysql_query($query, $db) or die(mysql_error($db));  

    while ($row = mysql_fetch_array($result3))  
    {  
    echo "<td>" . "<input type=number name=locid value=" .$row['locid']." </td>";
    }
    ?>
    <?php
    echo "<td>" . "<textarea cols=15 rows=3 name=comment ". " </td>";
    echo "</textarea>" . "</td>";
//echo "<td>" . "<input type=hidden name=hidden value=" .$row['id']."   </td>";
    echo "<td>" . "<input type=submit name=delete value=Delete" ." </td>";
    echo "</tr>";
    echo "</form>";

    mysql_close($db);
?>
</table>
<br />
<form align="right" method="post"action="insertattend.php" >
<input type="submit" value="submit">
    </form>
    </body>
    </html>


    <?php 

    // create connection variables;

    $host = "localhost";
    $user = "root";
    $pass = "";
    $dbname = "my_attendance";
    $prefix = "";

    // establishing connection

    $dbconnection = mysql_connect($host, $user, $pass)
    or die ("could not connect to  database");

    // select the db

    mysql_select_db($dbname, $dbconnection) or die("could not select database");
    // posting the values from student table
    $clnm = mysql_real_escape_string($_POST['classid']);

    $stfn = mysql_real_escape_string($_POST['fname']);
    // end of student table

    // new column added
    $dt = mysql_real_escape_string($_POST['date']);

    $fg = mysql_real_escape_string($_POST['flag']);
    //end of new column
    //posting values from  teacher table

    $tid = mysql_real_escape_string($_POST['teacherid']);

    $lid = mysql_real_escape_string($_POST['locid']);

    // end of teacher table

    //new columns added

    $cmt = mysql_real_escape_string($_POST['comment']);

    mysql_query("INSERT INTO attendance(classid, studentid, dateid, flag, 
    teacherid,    locid, comments) 
    VALUES('$clnm', '$stfn', '$dt', '$fg', '$tid', '$lid', '$cmt')");

    echo "<br>";
    echo "values inserted successfully!!!!";
    mysql_close($dbconnection);

    ?>

0 个答案:

没有答案