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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看