插入phpmyadmin数据库无法正常工作

时间:2016-03-21 15:50:37

标签: php jquery

这段php代码无法正常工作,因为我希望它将表单数据添加到数据库中的相应字段中。按提交时没有任何反应。数据库中的字段如下; PROP_ID
prop_title
prop_address
prop_postcode
prop_img
prop_radius
prop_bedrooms
prop_type
prop_price
prop_course
prop_desc
prop_share
prop_gender
prop_pets
prop_furnished
prop_smoking
prop_bathroom
prop_tv
prop_roomtype
prop_parking

<?php
    session_start(); 
    if (!isset($_SESSION["user_login"])) {
       header("Location: sign_up.php");
    } else {
          $username = $_SESSION["user_login"];
    }

    include ("connect.php");
    ?>

    <!doctype html>
    <html>
    <head>
        <title>Add a Property</title>
      <meta charset="utf-8">
      <link rel="stylesheet" type="text/css" href="css/index.css">
        <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

    </head>
    <body>

    <div class="whole_page_div" style="width:100%; height:935px;">
            <div class="container-fluid" style="margin-top: 15px;">
                    <div class="row">
                    <div class="col-md-12">
                    <div class="logo" style="margin-left: 750px;"><a href="index.php"><img class="logo" src="images/logo.png"/></a></div>
                     <a href="logout.php"> <button type="submit" class="btn btn-primary" name="logout" value="Log out" style="background-color:#337AB7; margin-top: -130px; margin-left: 1600px; ">Log Out</button></a>

                     <a href="landlord_profile.php"> <button type="submit" class="btn btn-primary" name="back" value="My Profile" style="background-color:#337AB7; margin-top: -150px; margin-left: 200px; ">My Profile</button></a>

                    </div>


    <hr>
        <nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
        <div class="container topnav">


                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand topnav" href="#">MyAstonSpace</a>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#Home">Home</a>
                        </li>
                        <li>
                            <a href="#Undergraduate Information">Undergraduate Information</a>
                        </li>
                        <li>
                            <a href="#Post-Grad Information">Post-Grad Information</a>
                        </li>
                         <li>
                            <a href="#International Students">International Students</a>
                        </li>
                         <li>
                            <a href="#Contact Us ">Contact Us </a>
                        </li>
                    </ul>
                </div>
                <!-- /.navbar-collapse -->
          </div>
            <!-- /.container -->
        </nav>

    <!-------------------------------------------------------------------------------------------------->
    <?php

    if(isset($_POST['prop_post'])){

        /// Variables
        $prop_title = $_POST['prop_title'];
        $prop_add = $_POST['prop_add'];
        $prop_postcode = $_POST['prop_postcode'];
        $prop_bed = $_POST['prop_bed'];
        $prop_bath = $_POST['radiobathroom'];
        $prop_type = $_POST['prop_type'];
        $prop_room = $_POST['radioroom'];
        $prop_price = $_POST['prop_price'];
        $prop_gender = $_POST['radiogender'];
        $prop_pets = $_POST['radiopets'];
        $prop_furnished = $_POST['radiofurnished'];
        $prop_smoke = $_POST['radiosmoke'];
        $prop_tv = $_POST['radiotv'];
        $prop_parking = $_POST['radioparking'];
        $prop_desc = $_POST['prop_desc'];



        //getting the image
        $prop_image = $_FILES['prop_image']['name'];
        $prop_image_tmp = $_FILES['prop_image']['tmp_name'];

        move_uploaded_file($prop_image_tmp,"includes/prop_img/$prop_image_tmp");

        $insert_property = "INSERT INTO properties (prop_id,prop_title,prop_address,prop_postcode,prop_img,prop_radius,prop_bedrooms,prop_type,prop_price,prop_course,prop_desc,prop_share,prop_gender,prop_pets,prop_furnished,prop_smoking,prop_bathroom,prop_tv,prop_roomtype,prop_parking) values ('','$prop_title','$prop_add','$prop_postcode','$prop_image','','$prop_bed','$prop_type','$prop_price','','$prop_desc','','$prop_gender','$prop_pets','$prop_furnished','$prop_smoke','$prop_bath','$prop_tv','$prop_room','$prop_parking')";

        $insert_prop = mysqli_query($connect, "$insert_property");

        if ($insert_prop){
            echo"Property has been uploaded.";


            }else {
                echo"Your advertisment could not be uploaded.";

                }

        }

    ?>



     <div class="container" style="float:left; padding-left:40px;">
      <h3>Add a New Property to MyAstonSpace</h3>
      <form action="" method="POST" enctype="multipart/form-data" role="form">
        <div class="form-group" style="width:750px;">
          <label for="Title">Title:</label>
          <input type="Title" class="form-control" name="prop_title" placeholder="Enter Title" >
        </div>
        <div class="form-group">
          <label for="Address">Address:</label>
          <input type="Address" class="form-control" name="prop_add"  placeholder="First Line, Town, City, County" style="width:600px;" >
          <input type="Address" class="form-control" name="prop_postcode"  placeholder="Postcode" style="width:275px; margin-left:625px; margin-top:-34px;" >
        </div>
        <div class="form-group" style="width:250px;">
          <label for="sel2">No of bedrooms:</label>
          <select class="form-control" name="prop_bed" id="sel2" >
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
          </select>
          <br/>
          <hr/>

           <!------Bathrooms check box ---->
     <form role="form">
    <label for="Bathrooms"> Bathrooms: </label>
        <label class="radio-inline">
          <input type="radio" name="radiobathroom">Shared
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiobathroom">Private
        </label>
      </form>
     <br/>
     <br/>

          <label for="sel1">Type of Property:</label>
          <select class="form-control" name="prop_type" id="sel3" >
            <option>Halls</option>
            <option>Flat</option>
            <option>Terrace Home share</option>
            <option>Semi Detactched Home share</option>
          </select>
               <br/>
          <hr/>


          <!------Room Type check box ---->
    <form role="form">
    <label for="Room Type"> Room Type: </label>
        <label class="radio-inline">
          <input type="radio" name="radioroom">Single Bed Room
        </label>
        <label class="radio-inline">
          <input type="radio" name="radioroom">Double Bed Room 
        </label>
        <label class="radio-inline">
          <input type="radio" name="radioroom">Triple Bed Room
        </label>
      </form>
     <br/>
     <br/>
          <div class="form-group">
          <label for="Price">Price(£):</label>
          <input type="Price" class="form-control" name="prop_price"  placeholder="Enter Price" >
        </div> 
        </div>

    </div>

    <!------Gender check box ---->
    <div class="container" style="font-size:17px; width:auto; position:absolute; left:950px; top:250px;">
    <center>
     <form role="form">
    <label for="Gender"> Gender: </label>
        <label class="radio-inline">
          <input type="radio" name="radiogender">Boys
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiogender">Girls
        </label>
            <label class="radio-inline">
          <input type="radio" name="radiogender">Both
        </label>
      </form>

     <hr/>




      <!------Pets check box ---->
      <form role="form">
    <label for="Pets"> Pets: </label>
        <label class="radio-inline">
          <input type="radio" name="radiopets">Allowed
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiopets">Not Allowed
        </label>
      </form>

      <hr/>

      <!------Furnished check box ---->
     <form role="form">
    <label for="Furnished"> Furnished: </label>
        <label class="radio-inline">
          <input type="radio" name="radiofurnished">Furnished
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiofurnished">Unfurnished
        </label>
      </form>

     <hr/>

      <!------Smoking check box ---->
     <form role="form">
    <label for="Smoking"> Smoking: </label>
        <label class="radio-inline">
          <input type="radio" name="radiosmoke">Allowed
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiosmoke">Not Allowed
        </label>
      </form>

     <hr/>



     <!------Television check box ---->
    <form role="form">
    <label for="Television"> Television: </label>
        <label class="radio-inline">
          <input type="radio" name="radiotv">Allowed
        </label>
        <label class="radio-inline">
          <input type="radio" name="radiotv">Not Allowed
        </label>
      </form>
     <hr/>

     <!------Parking check box ---->
      <form role="form">
    <label for="Parking"> Parking: </label>
        <label class="radio-inline">
          <input type="radio" name="radioparking">Free Parking
        </label>
        <label class="radio-inline">
          <input type="radio" name="radioparking">Pay and Display 
        </label>
        <label class="radio-inline">
          <input type="radio" name="radioparking">Additional monthly Charge
        </label>
      </form>

      <hr/>
        <div class="form-group">
        <label for="image">Insert image :</label>
        <input type="file" name="prop_image">
        </div>

        <div class="form-group" style="width:750px;">
          <label for="Description">Description:</label>
          <input type="Description" class="form-control" name="prop_desc"  placeholder="Enter Description" >
        </div>

        <div class="submit_button" style="float:right;">
        <button type="submit" class="btn btn-primary" name="prop_post" style=" background-color:#337AB7; color:white;">Submit</button>
         </div>
      </form>
      </center>
    </div>

此外,我希望这些子标题选项卡在同一页面上显示不同的页面,而无需刷新页面或将用户重定向到新页面。我相信我将不得不使用JQuery。我希望信息显示在页面中心的div面板中。

    <?php
    function getprop (){
        global $connect;

        $getprop = mysqli_query($connect,"SELECT * FROM properties");

        while ($rowprop = mysqli_fetch_array($getprop)){

            $prop_id = $rowprop['prop_id'];
            $prop_title = $rowprop['prop_title'];
            $prop_address = $rowprop['prop_address'];
            $prop_img = $rowprop['prop_img'];
            $prop_radius = $rowprop['prop_radius'];
            $prop_bedrooms = $rowprop['prop_bedrooms'];
            $prop_type = $rowprop['prop_type'];
            $prop_price = $rowprop['prop_price'];

            echo "
                <div class='singleproperty'>

                <h3>$prop_title</h3>
            "   ;       

            }


        }


    ?>
    <div class="container-fluid">
  <h3>Your Profile <h5> Landlord </5></h3>
  <ul class="nav nav-pills nav-stacked" style="width:300px;">
     <li><a href="#">Personal Information</a></li> 
    <li> <a class="dropdown-toggle" data-toggle="dropdown" href="landlord_profile.php"> My Properties <span class="caret"></span></a>
    <ul class="dropdown-menu">
      <li><a href="landlord_addproperty.php">Add a Property</a></li>
      <li><a href="#">Edit your properties</a></li>
    </ul>
   </li>

    <li><a href="#">Upload Profile Image</a></li>
    <li><a href="deactivate_myaccount.php">Deactivate My Account</a></li>
    <li><a href="#">    Change Password </a></li>


  </ul>
</div>


<center>
<div class="panel panel-default" style="width: 1200px; height: 400px; margin-top: -200px; margin-left: 100px; border: 2px solid blue;  " >
    <div class="panel-body" style="text-align:center; margin-left:30px; margin-bottom:10px;"> 
        <div class="listproperties">
        <?php
        getprop();
        ?>
        </div>

     </div>
</div>
</center>

0 个答案:

没有答案
相关问题