douhuan1937 2014-08-26 02:02 采纳率: 0%
浏览 71
已采纳

无法使用php将数据插入mysql表

I have following form in html

<form method="post" enctype="multipart/form-data" />
                <fieldset>
                <legend>Activate Scheme</legend>
                <p>Date Of Draw</p>
                <p><input type="text" name="dateOfDraw" class="textBox" style="width:150px" /></p>

                <p>Time Of Draw</p>
                <p><input type="text" class="textBox" name="timeOfDraw" style="width:150px" /></p>

                <p>Enter scheme name</p>
                <p><input type="text" class="textBox" name="schemeName" style="width:150px" />
                </p>

                <p>Upload Image</p>
                <p><input type="file" name="image" id="image" /></p>

                <p><input name="scheme_button" type="submit" class="button1" value="Submit"></p>
                </fieldset>
        </form>

Problem is that their is no error when I execute the following query

<?php 
if(isset($_POST['submit_button']) && count($_POST)>0) {
    print_r($_POST);

    $dateOfDraw = $_POST['dateOfDraw'];
    $timeOfDraw = $_POST['timeOfDraw'];
    $schemeName = $_POST['schemeName'];
    $imageName = $_FILES['image']['name'];

    $destination = '../images/'.$imageName;
    $source = $_FILES['image']['tmp_name'];
    if(move_uploaded_file($source, $destination)) {
        echo 'file uploaded';
    } else {
        echo ' file not uploaded';
    }

    $sSQL = "INSERT INTO landing_page(dateOfDraw, timeOfDraw, schemeName, image) VALUES('$dateOfDraw','$timeOfDraw','$schemeName','$imageName')";
    echo $sSQL;
    if(!$sSQL){
        die(mysqli_query($con));
        }
    mysqli_query($con,$sSQL);

    //header("location: list_products.php");
}
                ?>

but when I check my data in a mysql database the rows are still empty. Please check it am I missing something or the php code is wrong. Note: I am using php version 5.5.16

  • 写回答

2条回答 默认 最新

  • duandu8892 2014-08-26 02:07
    关注

    The name of your submit button is scheme_button and that's exactly the thing that you need to $_POST.

     if(isset($_POST['scheme_button']) && count($_POST) > 0)
    

    You form doesn't have an action and it doesn't know where to go. So add one.

    <form method="post" action="index.php" enctype="multipart/form-data" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题