我想通过循环输入在一个表中提交多条记录,但只有一条记录首先进入数据库 - PHP / MYSQLI

I want to submit multiple record in one table through looping input but only one record is going in Database first - PHP / MYSQLI

提问人:Mehboob Ali 提问时间:12/18/2019 最后编辑:Rp9Mehboob Ali 更新时间:12/18/2019 访问量:46

问:

在这里,我正在为 e 创建系统

<?php  

				include("inc/config.php");
				include("inc/functions.php"); 
				
				
				if(isset($_REQUEST['submit'])){
	
	
				$acadimic_exam_id = $_REQUEST['id'];
				$subject_id = $_REQUEST['subject_id'];
				$exam_date = $_REQUEST['exam_date'];
				$exam_duration = $_REQUEST['exam_duration'];
				$total_marks = $_REQUEST['total_marks'];
				$passing_marks = $_REQUEST['passing_marks'];
				$upload_exam_paper = $_REQUEST['upload_exam_paper'];
				
				
				
				$string = "insert into  exam_deatils SET
				acadimic_exam_id = '".$acadimic_exam_id."',
				subject_id = '".$subject_id."',
				exam_date = '".$exam_date."',
				exam_duration = '".$exam_duration."',
				total_marks = '".$total_marks."',
				passing_marks = '".$passing_marks."', 
				upload_exam_paper = '".$upload_exam_paper."'"; 
				
				query($string);
				$msg="New Exam has been added successfully";
				header("location:make_exam.php?mess=$msg");	
					
		
		}
	
	
	
		 
?>
<!doctype html>
<html class="no-js" lang="en">
<!--<![endif]-->
	<?php  
	
	include("inc/head.php"); 
	 
	?>

<body>





	<?php  include("inc/lock-slider.php");  ?>
	 
	<?php include("inc/script-main.php");  ?>
	
	<?php include("inc/toolbar.php"); ?>
	
	<?php include("inc/header.php"); ?>
	
	<?php  include("inc/admininstrator.php"); ?>
	
	<?php  include("inc/left-menu.php"); ?>
	
	
	<section id="content" class="container_12 clearfix" data-sort=true>
			<h1 class="grid_12">All Current Exams</h1> 
			<div class="grid_12">
				<div class="box">
					<div class="header">
					 
						<h2>Dynamic Table (Current Exam) </h2> 
						
					</div>
					<div class="content"> 
					
					<form action="" method="POST">
						<table class="dynamic styled" data-filter-Bar="always" data-table-tools='{"display":false}'>
						
							<thead>
								<tr>
									 
									<th>Sr No</th>
									<th>Subjects</th>
									<th>Exam Date</th>
									<th>Duration (HR)</th>
									<th>Total Marks</th>
									<th>Passing Marks</th>
									<th>Upload Exam Paper</th>
									
									
								</tr>
							</thead>
							<tbody>
							
							 <?php
							 
					 
							 $getting_subjects = "Select * from tbl_subjects where class_id='".$_REQUEST['class_id']."'";
							 $sub_result = query($getting_subjects);
							 $sr_no = 1;
							 while($sub_res = mysqli_fetch_array($sub_result))
							 
							 
							 {
							 
							 ?>
									<tr> 
									<td><?php echo $sr_no;  ?></td>
									<td><?php echo $sub_res['subject_name'];  ?></td>
									<td><input type="date" name="exam_date" id="exam_date"/></td>
									<td>
									<select name="exam_duration" id="exam_duration">
											<option value="0:30">0:30</option>
											<option value="0:45">0:45</option>
											<option value="0:60">0:60</option>
											<option value="1:00">1:00</option>
											<option value="1:30">1:30</option>
											<option value="1:45">1:45</option>
											<option value="2:00">2:00</option>
											<option value="2:30">2:30</option>
											<option value="2:45">2:45</option>
											<option value="3:00">3:00</option>
											<option value="3:30">3:30</option>
											<option value="3:45">3:45</option>
											<option value="4:00">4:00</option>
									</select>
									
									</td>
									<td><input type="text" name="total_marks" id="total_marks"/></td>
									<td><input type="text" name="passing_marks" id="passing_marks"/></td>
									<td><input type="file" name="upload_exam_paper" id="upload_exam_paper"/></td>
								</tr>
								
								<tr>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
										
										<?php
										
										$sr_no++;
										
										}
										
										?>								
									<td>
									
	<input type="submit" name="submit" id="submit" value="Submit" >
	<a href=""><input type="submit" name"" id="" value="Cancel"></a>
	
									</td>
									
								</tr>
								 
								 
							</tbody>
							
							 
						</table>
						</form>
					</div>
				</div>
			</div>
			
		
		</section>
	</div>
	
	<?php  include("inc/footer.php");?>
	
	
	 
	
	
	<script>
		$$.loaded();
	</script>
	<!--[if lt IE 7 ]><script defer src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script> <script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script><![endif]-->
</body>
 
</html>

使用 PHP 进行 xamination,我创建了两个表,一个是获取基本考试详细信息,另一个是获取与该考试 ID 相关的其他考试详细信息。根据与该考试相关的所有科目,我获得了完美的记录,但只有一项记录排在前列,其他学科及其领域没有获得记录。.. . . .我正在将简单的PHP与MySQLI一起使用 为了你们可爱的编程语言,请大家帮助我。我从过去 5 天开始就被困在里面enter image description here

enter image description here

PHP 循环 mysqli

评论

0赞 Dharman 12/18/2019
您的代码容易受到 SQL 注入的攻击。您应该使用预准备语句。查看 stackoverflow.com/q/7537377/1839439

答:

0赞 in need of help 12/18/2019 #1

提交表单后,服务器端只有一个插入。 您还必须注意,提交后,页面将停止运行,并且不会发生其他提交。 听起来您想在客户端聚合数据并将循环移动到提交处理中