doucha7329 2019-06-20 00:44
浏览 19

尝试将db中的选定行插入到新表中

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测