正在处理表单的注册表单部分的AM包含直接从我的数据库中获取的数据,发现很难将相同的数据插入到sql db中的新表中。
我正在使用Apache 2.4.23和php 7.0
这是代码
<div class="form-group">
// Fetching data from db using select
<?php
$query= "SELECT * FROM class";
$stmt=$conn->prepare($query);
$stmt->execute();
$result1=$stmt->get_result();
?>
<label>CLASS</label>
<select class="form-control">
<option>Select Class</option>
// i used while loop to fetch the row
<?php while($row=$result1->fetch_assoc()){ ?>
//This is where am having issues inserting the data to db
<option value="clasname"><?= $row['clasname']; ?></option>
<?php }?>
</select>
</div>
//这是代码的插入部分
if(isset($_POST['add'])){
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$reg_no=$_POST['reg_no'];
$gender=$_POST['gender'];
$class=$_POST['class'];
$section=$_POST['section'];
$photo=$_FILES['image']['name'];
$upload="uploads/".$photo;
$query="INSERT INTO add_student(fname,lname,reg_no,gender,class,section,photo)VALUES('$fname','$lname','$reg_no','$gender','$class','$section','$upload')";
$stmt=$conn->prepare($query);
$stmt->bind_param("sssssss", $fname,$lname,$reg_no,$gender,$class,$section,$upload);
$stmt->execute();
move_uploaded_file($_FILES["image"]["tmp_name"], $upload);
header('location:viewstudent.php');
$_SESSION['response']="Succesfully inserted to the Database!";
$_SESSION['res_type']="Success";
}
我希望将其插入数据库,除所选行外,没有成功保存其他表单数据的错误消息