2017-05-05 1 views
0

하나의 양식을 사용하여 "휴가의 집"을 업로드해야합니다. 그러나 속성에 필요한 세부 정보는 속성, 가격, 카운티 및 이미지와 같은 여러 테이블에 저장됩니다. 내가 업로드를 클릭하면 속성이 데이터베이스에 업로드되지하나의 양식을 사용하여 여러 데이터베이스 테이블에 업로드

<?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); 

:

<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> 

이 내 submitprop 코드 : 이것은 내 양식 코드입니다. 내 코드에서 놓친 부분이 있습니까?

+0

는 "등록 INTO INSERT (ID, 이름, 설명, County_ID) VALUES (NULL, '$의 sentpropname', '$의 sentpropdesc', NULL)"= $ insertquery1 에코보십시오; 그런 다음 phpmyadmin –

+0

에서이 키를 실행하고 기본 키 ID를 입력하십시오. $ insertquery1 = "등록 정보 (이름, 설명, County_ID) 값 ('". $ sentpropname. "', '". $ sentpropdesc ."', 없는)"; –

+0

당신의 ID 파일은 Auto-Increment입니다. – Akintunde007

답변

0

$tableNames = ['one','two','three']; 

    foreach($value in $tableNames){ 

    $query = "insert into '".$value."' values()"; 
    mysqli_query($conn, $query); 
    } 
관련 문제