gpt4 book ai didi

php - 值不会插入到数据库的表中

转载 作者:可可西里 更新时间:2023-11-01 08:29:22 25 4
gpt4 key购买 nike

<分区>

我在学校电子学习管理系统上工作,遇到问题,在提交时,表单值不会插入到数据库表中,除非它在表单提交中显示成功消息“类(class)已成功添加”,但是表保持为空,意味着我的表中没有添加任何数据。有什么建议吗?我的代码是:

添加类.php

<form method="post" id="add_class">
<label>Class Name:</label>
<input type="hidden" name="session_id" value="<?php echo $session_id; ?>">
<select name="class_id" class="" required>
<option></option>
<?php $query = mysql_query("select * from class order by class_name");
while($row = mysql_fetch_array($query)){
?>
<option value="<?php echo $row['class_id']; ?>"><?php echo $row['class_name']; ?></option>
<?php } ?>
</select>
<label>Subject:</label>
<select name="subject_id" class="" required>
<option></option>
<?php
$query = mysql_query("select * from subject order by subject_code");
while($row = mysql_fetch_array($query)){
?>
<option value="<?php echo $row['subject_id']; ?>"><?php echo $row['subject_code']; ?></option>
<?php } ?>
</select>
<label>School Year:</label>
<?php
$query = mysql_query("select * from school_year order by school_year DESC");
$row = mysql_fetch_array($query);
?>
<input id="" class="span5" type="text" class="" name="school_year" value="<?php echo $row['school_year']; ?>" >
<button name="save" class="btn btn-success"><i class="icon-save"></i> Save</button>
</form>
<script>
jQuery(document).ready(function($){
$("#add_class").submit(function(e){
e.preventDefault();
var _this = $(e.target);
var formData = $(this).serialize();
$.ajax({
type: "POST",
url: "add_class_action.php",
data: formData,
success: function(html){
if(html=="true")
{
$.jGrowl("Class Already Exist", { header: 'Add Class Failed' });
}else{
$.jGrowl("Classs Successfully Added", { header: 'Class Added' });
var delay = 1000;
setTimeout(function(){ window.location = 'dasboard_teacher.php' }, delay);
}
}
});
});
});
</script>

add_class_action.php

<?php 
include('dbcon.php');
$session_id = $_POST['session_id'];
$subject_id = $_POST['subject_id'];
$class_id = $_POST['class_id'];
$school_year = $_POST['school_year'];
$query = mysql_query("select * from teacher_class where subject_id = '$subject_id' and class_id = '$class_id' and teacher_id = '$session_id' and school_year = '$school_year' ")or die(mysql_error());
$count = mysql_num_rows($query);
if ($count > 0){
echo 'true';
}else{
mysql_query("insert into teacher_class (teacher_id,class_id,subject_id,thumbnails,school_year) values('$session_id','$class_id','$subject_id','admin/uploads/thumbnails.jpg','$school_year')")or die(mysql_error());
$teacher_class = mysql_query("select * from teacher_class order by teacher_class_id DESC")or die(mysql_error());
$teacher_row = mysql_fetch_array($teacher_class);
$teacher_id = $teacher_row['teacher_class_id'];
$insert_query = mysql_query("select * from student where class_id = '$class_id'")or die(mysql_error());
while($row = mysql_fetch_array($insert_query)){
$id = $row['student_id'];
mysql_query("insert into teacher_class_student (teacher_id,student_id,teacher_class_id) value('$session_id','$id','$teacher_id')")or die(mysql_error());
echo "yes";
}
}
?>

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