单击时,“提交”按钮不会执行任何操作

时间:2016-03-17 16:05:19

标签: php forms sql-insert

我正在尝试将此表单数据插入数据库。但是当我按提交时没有任何反应。我的数据库中有以下字段; PROP_ID
prop_title
prop_address
prop_postcode
prop_img
prop_radius
prop_bedrooms
prop_type
prop_price
prop_course
prop_desc
prop_share

<?php
session_start(); 

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_type = $_POST['prop_type'];
    $prop_price = $_POST['prop_price'];
    $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) values ('','$prop_title','$prop_add','$prop_postcode','$prop_image','','$prop_bed','$prop_type','$prop_price','','$prop_desc','')";

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

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


        }

    }

?>



 <div class="container" style="height:550px;">
  <h3>Add a New Property to MyAstonSpace</h3>
  <form action="landlord_addproperty.php" method="POST" enctype="multipart/form-data" role="form">
    <div class="form-group">
      <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:750px;" >
      <input type="Address" class="form-control" name="prop_postcode"  placeholder="Postcode" style="width:350px; float:right; margin-top:-33px;" >
    </div>
    <div class="form-group">
      <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>
       <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>
      <div class="form-group">
      <label for="Price">Price(£):</label>
      <input type="Price" class="form-control" name="prop_price"  placeholder="Enter Price" >
    </div> 
    </div>
    <form action="" method = "POST" enctype="multipart/form-data">
    <input type="file" name="prop_image"  >
    </form>
    <div class="form-group">
      <label for="Description">Description:</label>
      <input type="Description" class="form-control" name="prop_desc"  placeholder="Enter Description" >
    </div>

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



<!-------------------------------------------------------------------------------------------------->

<?php
include ("footer-inc.php");
?>

2 个答案:

答案 0 :(得分:2)

我们无法在其他表单中嵌套表单

<form name='form1'>
      <form name='form2'>

      </form>
</form>

为什么要使用其他表单上传

<form action="" method = "POST" enctype="multipart/form-data">
    <input type="file" name="prop_image"  >
    </form>

如果从那里删除此表单标记,它将起作用。只需添加此行代码

<input type="file" name="prop_image"  >

答案 1 :(得分:1)

<button type="button" name="myBotton" value="num">
<script type="text/javascript">
function buttonAction(){

// code here

}

document.form.myBotton.onclick = buttonAction;
</script>
</button>