使用一个表单上传到多个数据库表

时间:2017-05-05 12:42:13

标签: php html database forms insert

我需要使用一个表单上传“度假屋”。但该属性所需的详细信息存储在多个表中 - 属性,价格,县和图像。这是我的表单代码:

<form class="pure-form pure-form-stacked" action="propsubmit.php" 
method="post" name="uploadproperty"  enctype="multipart/form-data" 
style="margin-left: 20px; color:black">
    <fieldset><br>

        <label for="propertyname" class="button button-alt" 
style="background-color:white" >Property Name:</label>
        <input id="propertyname" name="propertyname" type="text" placeholder="Enter name here.... " size="50" required="required"/><br>

        <label for="description" class="button button-alt" style="background-color:white "> Description:</label>
        <textarea rows="10" cols="100" name="description" placeholder="Enter description here...." required="required"></textarea><br>    

        <label for="county" class="button button-alt" style="background-color:white">County:</label>
        <select id="county" name="county" placeholder="Choose County" required="required">
        <option value="antrim">Antrim</option>
        <option value="down">Down</option>
        <option value="derry">Derry</option>
        </select>

        <label for="amin" class="button button-alt" style="background-color:white" >Autumn minimum price:</label>
        <input id="amin" name="amin" type="text" placeholder="Price.... " size="10" required="required"/><br>

        <label for="amax" class="button button-alt" style="background-color:white" >Autunm maximum price:</label>
        <input id="amax" name="amax" type="text" placeholder="Price.... " size="10" required="required"/><br>

        <label for="spmin" class="button button-alt" style="background-color:white" >Spring minimum price:</label>
        <input id="spmin" name="spmin" type="text" placeholder="Price.... " size="10" required="required"/><br>

        <label for="spmax" class="button button-alt" style="background-color:white" >Spring maximum price:</label>
        <input id="spmax" name="spmax" type="text" placeholder="Price.... " size="10" required="required"/><br>

        <label for="sumin" class="button button-alt" style="background-color:white" >Summer minimum price:</label>
        <input id="sumin" name="sumin" type="text" placeholder="Price.... " size="10" required="required"/><br>

        <label for="sumax" class="button button-alt" style="background-color:white" >Summer maximum price:</label>
        <input id="sumax" name="sumax" type="text" placeholder="Price.... " size="10" required="required"/><br>  

        <label for="wmin" class="button button-alt" style="background-color:white" >Winter minimum price:</label>
        <input id="wmin" name="wmin" type="text" placeholder="Price.... " size="10" required="required"/><br>  

        <label for="wmax" class="button button-alt" style="background-color:white" >Winter maximum price:</label>
        <input id="wmax" name="wmax" type="text" placeholder="Price.... " size="10" required="required"/><br>       

        <label for="propimage"  class="button button-alt" style="background-color:white">Images:</label> 
        <input name="propimgs" type="file" multiple="required"/><br>  





        <br>

        <button type="submit" class="button button-alt" name="search">Upload Property</button>
        <button type="reset" class="button button-alt">Reset</button>


          </fieldset>
  </form>

这是我的提交代码:

<?php
include("../connections/conn.php");



$sentpropname = $_POST['propertyname'];
$sentpropdesc = $_POST['description'];

$insertquery1 = "INSERT INTO Properties (ID, Name, Description, County_ID)
                    VALUES (NULL, '$sentpropname', '$sentpropdesc', NULL)";
$result1 = mysqli_query($conn, $insertquery1);

$sentpropcounty = $_POST['county'];

$insertquery2 = "INSERT INTO County (ID, County)
                    VALUES (NULL, '$sentpropcounty')";
$result2 = mysqli_query($conn, $insertquery2);

$filename = $_FILES['propimgs']['name']; 
$filetemp = $_FILES['propimgs']['tmp_name'];


move_uploaded_file($filetemp,"../images/$filename");


$insertquery3 = "INSERT INTO Image (ID, Property_ID, Path) VALUES (NULL, 0, 
'$filename')";
$result3 = mysqli_query($conn, $insertquery3);



$sentpriceautummin = $_POST['amin'];
$sentpriceautummax = $_POST['amax'];
$sentpricespringmin = $_POST['spmin'];
$sentpricespringmax = $_POST['spmax'];
$sentpricesummermin = $_POST['sumin'];
$sentpricesummermax = $_POST['sumax'];
$sentpricewintermin = $_POST['wmin'];
$sentpricewintermax = $_POST['wmax'];

$insertpricequery = "INSERT INTO Prices"
  . "(id, Property_ID, AutumnMinPrice, AutumnMaxPrice, SpringMinPrice, "
  . "SpringMaxPrice, SummerMinPrice, SummerMaxPrice, WinterMinPrice, 
  WinterMaxPrice)"
  . "VALUES(0, 0, '$sentpriceautummin', '$sentpriceautummax', "
  . "'$sentpricespringmin', '$sentpricespringmax', '$sentpricesummermin', "
  . "'$sentpricesummermax', '$sentpricewintermin', '$sentpricewintermax')";

      $resultpricequery = mysqli_query($conn, $insertpricequery) or die(mysqli_error($conn));
      mysqli_close($conn);

单击上载时,该属性不会上传到数据库中。我的代码中是否有任何特定的错误?

1 个答案:

答案 0 :(得分:0)

试试这个

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

    <script src="../resources/sap-ui-core.js"
            id="sap-ui-bootstrap"
            data-sap-ui-language="en"
            data-sap-ui-libs="sap.ui.commons,sap.ui.table"
            data-sap-ui-compatVersion="edge"
            data-sap-ui-preload="async"
            data-sap-ui-theme="sap_bluecrystal">
    </script>
    <script>
        sap.ui.localResources("my_project");
        sap.ui.localResources("util");
        sap.ui.localResources("i18n");


            var view = sap.ui.view({type: sap.ui.core.mvc,
                id: "xsodata",
                viewName: "my_project.view.xsodatatest"

            });
            view.placeAt("content");

    </script>
</head>
<body class="sapUiBody" role="application">
<div id="content">
</div>
</body>
</html>