php - 为什么我的 PHP 记录没有被插入

标签 php mysql sql

美好的一天!

大家能帮我检查一下为什么我无法使用表格上的 chekbox 选项插入记录吗?

请帮忙..

这是我的代码...

--为教师 HTML 表单添加主题负载--(studsub.php)

<form action="setsubject.php" method="post">
 <?php
include('../connect.php');
$id=$_GET['id'];
$result = mysql_query("SELECT * FROM student WHERE id='$id'");
        while($row = mysql_fetch_array($result))
            {
                //$course=$row['course'];
                //$year=$row['yearlevel'];
                //$section=$row['section'];
                $idnumber=$row['idnumber'];
                echo '<br/>';
                echo $row['lname'].", ".$row['fname'];

?> 
<input type="hidden" name="studidnum" value="<?php echo $rows['idnumber']?>">
<?php }
?>
<br/><br/>
<label for="filter">Filter</label> <input type="text" name="filter" value="" id="filter" />


  <table cellpadding="1" cellspacing="1" id="resultTable">
            <thead>
                <tr>
                  <th  style="border-left: 1px solid #C1DAD7"><label>Assign</label></th>
                    <th  style="border-left: 1px solid #C1DAD7"> Subject ID </th>
                    <th>Title</th>
                    <th>Units</th>
              </tr>
            </thead>
            <tbody>


            <?php
                include('../connect.php');
                $result = mysql_query("SELECT * FROM tbl_cur_sub where status='1' ");
                while($row = mysql_fetch_array($result))
                    {
                        echo '<tr class="record">';
                    echo '  <td>' . '<input type="checkbox" name="subject[]" value="'.$rows['code'].'" />' . '</td> ' ;
                        echo '<td  style="border-left: 1px solid #C1DAD7">'.$row['code'].'</td>';
                        echo '<td><div align="left">'.$row['subject'].'</div></td>';
                        echo '<td><div align="left">'.$row['units'].'</div></td>';

                        echo '</tr>';
                    }
                ?> 
            </tbody>
  </table>
  <br/>
  Course<br>
  <select name="course" class="ed">
    <?php
        include('../connect.php');
        $results = mysql_query("SELECT * FROM course");
        while($rows = mysql_fetch_array($results))
            {
            echo '<option>'.$rows['coursecode'].'</option>';
            }
        ?>
  </select>
  <select name="yearlevel" class="ed">
    <?php
        include('../connect.php');
        $results = mysql_query("SELECT * FROM tbl_yrlevel");
        while($rows = mysql_fetch_array($results))
            {
            echo '<option>'.$rows['yearlevel'].'</option>';
            }
        ?>
  </select>
  <select name="section" class="ed">
    <option>A</option>
    <option>B</option>
    <option>C</option>
    <option>D</option>
  </select>
  <br>
  <br>
  <input type="submit" value="Assign" id="button1">
</form>

--提交页面--(setsubject.php)

<?php
include('../connect.php');

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str)
    {
        $str = @trim($str);
        if(get_magic_quotes_gpc())
            {
            $str = stripslashes($str);
            }
        return mysql_real_escape_string($str);
    }
//Sanitize the POST values
$course = clean($_POST['course']);
$section = clean($_POST['section']);
$yearlevel = clean($_POST['yearlevel']);
$studidnum=$_POST['studidnum'];
$subject=$_POST['subject'];
$N = count($subject);
for($i=0; $i < $N; $i++)
{
    mysql_query("INSERT INTO studentsubject (student, subject, section, course, level) VALUES ('$studidnum', '$subject[$i]','$section','$course', '$level')");
    }

header("location: student.php");
mysql_close($con);
?>

--我的数据库--

表:学生科目 字段:学生、学科、部门、类(class)、级别

提前感谢您的帮助..

最佳答案

尝试
mysql_query("SELECT * FROM tbl_cur_sub where status=1 ");

关于php - 为什么我的 PHP 记录没有被插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18778060/

相关文章:

php - fatal error : Uncaught exception 'PDOException' with message

php - 如何从搜索中获取第一个 YouTube 视频的 URL?

javascript - 网页打印按钮不起作用

php - preg_replace div(或任何东西)与 class=removeMe

mysql - 基于今天日期的 SQL 查询

php - SQL 查询(Zend 框架)

mysql - 如何检索mysql中的最后一条记录?

Mysql select from table 移动一列

sql - 如何在 MySQL 数据库中显示多个值?

mysql - 创建一个新表,其中为另一个表中的每个元素创建一列