php - 未在数据库中发布的值

标签 php mysql

我想记录特定类(class)的出勤情况并将值存储在数据库中。 我已使用 INNER JOIN 从两个表中获取数据,并在表单名称出勤中使用这些表值。

现在,一旦我使用表单参加考勤,我想将该值存储在我的数据库中,因此我创建了另一个文件名 insertattendance.php。

问题是它显示 undefined index 变量。例如 undefined index classid ..等 所以我尝试在 *if(isset($_POST['submit'])* 中使用它,没有错误,但值未发布。

我的疑问是,因为我正在使用旧表的值,所以它是否显示错误? 告诉我我该怎么做?

出勤.php

<html>
<head>
<title>grade1</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
<tr>
<th>classid</th>
<th>studentid</th>
<th>teacherid</th>
<th>locid</th>
<th>date</th>
<th>flag</th>
<th>comments</th>
</tr>
<?php
include 'conn.php';
$query = "(SELECT  a.classid, a.fname, b.teacherid, c.locid
           FROM class_master c JOIN student_master a 
           ON c.classid = a.classid JOIN teacher_link b
           ON c.classid = b.classid 
           WHERE c.classid = 'grade1' )";
 $result = mysql_query($query);

$i=1;

while( $row = mysql_fetch_array($result))
{
echo "<form action=insertattend.php method=POST>";
echo "<tr>";
echo "<td>" . "<input name=classid[$i] type=text value=" .$row['classid']." </td>";
echo "<td>" . "<input name=fname[$i] type=text value=" .$row['fname']." </td>";
echo "<td>" . "<input name=teacherid[$i] type=number value=" 
.$row['teacherid']." </td>";
echo "<td>" . "<input type=number name=locid[$i] value=" .$row['locid']." </td>";
echo "<td>" . "<input name=date[$i] type=date value='date'></td>";

echo "<td>" . "<input type=radio id=attend name=attend[$i] value='present'>";?>P
<?php  echo "<input type=radio id=attend name=attend[$i] value='absent'>";?>A
<?php
echo"</td>";
echo "<td><input name=comment type=comment[$i] row=3 column=5></td>";
echo "</tr>";
 $i++;

}
 ?>
 </table>
 <input type="submit" value="submit">
 </form>
 </body>
 </html>

这是我的 Insertattendance.php 代码

<?php 

if (isset($_POST['submit'])){
include 'conn.php';
$clnm = mysql_real_escape_string($_POST['classid']);

$stfn = mysql_real_escape_string($_POST['fname']);

$dt = mysql_real_escape_string($_POST['date']);

$fg = mysql_real_escape_string($_POST['attend']);

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

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

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

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


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

最佳答案

修复您的 html 代码:

    <html>
<head>
    <title>grade1</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" width="200" height="200">
    <tr>
        <th>classid</th>
        <th>studentid</th>
        <th>teacherid</th>
        <th>locid</th>
        <th>date</th>
        <th>flag</th>
        <th>comments</th>
    </tr>
    <?php
    include 'conn.php';
    $query = "(SELECT  a.classid, a.fname, b.teacherid, c.locid
           FROM class_master c JOIN student_master a
           ON c.classid = a.classid JOIN teacher_link b
           ON c.classid = b.classid
           WHERE c.classid = 'grade1' )";
    $result = mysql_query($query);


    while( $row = mysql_fetch_array($result))
    {
        echo "<form action='insertattend.php' method='POST'>";
        echo "<tr>";
        echo "<td>" . "<input name=classid type=text value=" .$row['classid']." ></td>";
        echo "<td>" . "<input name=fname type=text value=" .$row['fname']." ></td>";
        echo "<td>" . "<input name=teacherid type=number value=" .$row['teacherid']." ></td>";
        echo "<td>" . "<input type=number name=locid value=" .$row['locid']." ></td>";
        echo "<td>" . "<input name=date type=date value='date'></td>";

        echo "<td>" . "<input type=radio id=attend name=attend value='present'>";?>P
        <?php echo "<input type=radio id=attend name=attend value='absent'>";?>A
        <?php
        echo"</td>";
        echo "<td><input name=comment type=comment row=3 column=5></td>";
        echo "</tr>";
        //echo "</form>";
      ?>
        <input type="submit" name="submit" value="submit">
        </form>
<?php } ?>
    <!--<form action="insertattend.php">-->
</table>

</body>
</html>

关于php - 未在数据库中发布的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20898059/

相关文章:

php - 获取最后一小时插入的最后一项

php - PHP如何智能缓存页面的特定部分?

mysql - 在sql中按月名分组

c# - EF 4.1/存储库/UnitOfWork/MySQL : There is already an open DataReader associated with this Connection which must be closed first

php - Laravel 5 - 配置子文件夹

mysql - 计数查询的未知列

php - 从表中选择数据,其中 COUNT 列从最大到最小

php - 用于分解配方列表元素的正则表达式语法

javascript - 使用 Longblob 数据类型从 mysql 数据库中损坏图像

php - MySQL 请求在 String 上返回空结果