AM working on a registration form part of the form contain data that was fetched direct from my db, am finding it difficult inserting same data into a new table in sql db.
Am working with apache 2.4.23 and php 7.0
Here is the code
<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>
// Here is the insert part of the code
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";
}
i expected it to be inserted to the db, no error messages other form data was saved successfully except the selected row