drju37335 2018-06-08 17:43
浏览 78

数据没有使用php mysql提交到数据库

I am using php and MySQL. When I submit the form data is not stored in the database table 'plantation_journal_nursery_details'. I am badly stuck here. Can anyone please advice me that how can I solve this problem?? Thanks in advance guys. codes are given below :

create_journal.php

<form action="data_fetch.php" action="post">
                        <div class="row">
                            <div class="col-sm-4">
                                <h4 style="font-size: 16px;padding-left: 15px;"><b>Nursery Location:</b></h4><br>
                                <div align="right" style="padding-right: 10px;">
                                    <label style="font-weight:300;font-size: 15px">Location:</label>
                                    <input type="text" name="location" id="location" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
                                    <label style="font-weight:300;font-size: 15px">Area:</label>
                                    <input type="text" name="area1" id="area1" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
                                    <label style="font-weight:300;font-size: 15px">type of Nursey:</label>
                                    <select  name="type_of_nursery" id="type_of_nursery" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                    </select><br><br>
                                    <label style="font-weight:300;font-size: 15px">Centranl Nursery Name:</label>
                                    <select  name="central_nursery_name" id="central_nursery_name" style="width:40%;height: 30px; margin-left: 10px; border-radius: 5px;">
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                    </select><br><br>
                                    <label style="font-weight:300;font-size: 15px">State Nursery Name:</label>
                                    <input type="text"  name="state_nursery_name" id="state_nursery_name"  style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <h4 style="font-size: 16px;padding-left: 15px;"><b>Size of Each Bed:</b></h4><br>
                                <div align="right" style="padding-right: 10px;">
                                    <label style="font-weight:300;font-size: 15px">Mother Bed Size:</label>
                                    <input type="text"  name="mother_bed_size" id="mother_bed_size"  style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
                                    <label style="font-weight:300;font-size: 15px">Quantity:</label>
                                    <input type="text" name="quantity_m" id="quantity_m" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br><br><br>
                                    <label style="font-weight:300;font-size: 15px">Source of Seed:</label>
                                    <select name="source_of_seed" id="source_of_seed" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                    </select><br><br>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div align="right" style="padding-right: 10px; padding-top: 40px">
                                    <label style="font-weight:300;font-size: 15px">Polypot Bed Size:</label>
                                    <input type="text" name="polypot_bed_size" id="polypot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
                                    <label style="font-weight:300;font-size: 15px">Quantity:</label>
                                    <input type="text" name="quantity_p" id="quantity_p" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br><br>
                                    <label style="font-weight:300;font-size: 15px">Hycopot Bed Size:</label>
                                    <input type="text" name="hycopot_bed_size" id="hycopot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
                                    <label style="font-weight:300;font-size: 15px">Quantity:</label>
                                    <input type="text" name="quantity_h" id="quantity_h" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div align="right" style="padding-right: 10px;">
                                <input class="btn btn-info" type="submit" name="submit16" value="Add" onclick="move7()">
                            </div>
                        </div>
                    </form>

data_fetch.php

    <?php
$con=mysqli_connect("localhost","root","","forestdb");
    if(isset($_POST['submit16'])){
    $location=$_POST['location'];
    $area1=$_POST['area1'];
    $type_of_nursery=$_POST['type_of_nursery'];
    $central_nursery_name=$_POST['central_nursery_name'];
    $state_nursery_name=$_POST['state_nursery_name'];
    $mother_bed_size=$_POST['mother_bed_size'];
    $quantity_m=$_POST['quantity_m'];
    $source_of_seed=$_POST['source_of_seed'];
    $polypot_bed_size=$_POST['polypot_bed_size'];
    $quantity_p=$_POST['quantity_p'];
    $hycopot_bed_size=$_POST['hycopot_bed_size'];
    $quantity_h=$_POST['quantity_h'];


    $query="SELECT plantation_journal_no from plantation_journal_basic_details where plantation_journal_no=(select max(plantation_journal_no) from plantation_journal_basic_details);";
    $res=mysqli_query($con,$query);
    $row=mysqli_fetch_assoc($res);
    $plantation_journal_no=$row['plantation_journal_no'];
    $sql="INSERT INTO `plantation_journal_nursery_details`(`plantation_journal_no`, `location`, `area`, `type_of_nursery`, `central_nursery_name`, `state_nursery_name`, `mother_bed_size`, `quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`, `hycopot_bed_size`, `quantity_h`) VALUES ('$plantation_journal_no','$location','$area1','$type_of_nursery','$central_nursery_name','$central_nursery_name','$mother_bed_size','$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p','$hycopot_bed_size','$quantity_h');";

    $result=mysqli_query($con,$sql);
    if($result){
        echo "<script>alert('data submitted.');</script>";
        header("Location:create_journal.php");
    }
}

?>

Frontend Table

Backend Table

  • 写回答

1条回答 默认 最新

  • dongxiangchan0743 2018-06-08 18:52
    关注

    Your insert query, before you edited your question, contained ...

    ...VALUES ('$plantation_journal_no',$configurarion','$slope','$water_table_in_...
    

    Notice that your single quotes aren't matched. You should have

    ...VALUES ('$plantation_journal_no','$configurarion','$slope','$water_table_in_...
    

    If you had checked for an error in your query you would have found this problem immediately. Code like this would have helped.

    if($result){
        echo "<script>alert('data submitted.');</script>";
        header("Location:create_journal.php");
    }
    else {
        die  $mysqli->error;
    }
    

    Pro tip: Format your code so you don't have to scroll horizontally to see entire queries. It's far easier to examine your queries and find mistakes that way. You can use php's heredoc syntax for string constants to do that.

    This is how it looks.

        $sql= <<<INSERTQUERY
    INSERT INTO `plantation_journal_nursery_details`
           (`plantation_journal_no`, `location`, `area`, `type_of_nursery`, 
            `central_nursery_name`, `state_nursery_name`, `mother_bed_size`, 
            `quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`, 
            `hycopot_bed_size`, `quantity_h`) 
      VALUES 
           ('$plantation_journal_no','$location','$area1','$type_of_nursery',
            '$central_nursery_name','$central_nursery_name','$mother_bed_size',
            '$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p',
            '$hycopot_bed_size','$quantity_h');
    INSERTQUERY;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line