gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:20:40 25 4
gpt4 key购买 nike

我想记录特定类(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com