使用jquery时无法通过.php文件连接?

时间:2014-06-05 07:38:06

标签: html mysql

我有一个在JQuery& amp;中设计的注册表。我有一个.php文件,其中写入数据插入查询。但是,当我点击表单的提交按钮.php文件不会调用。我已经提到过formaction =" insert.php"。虽然我已将文件夹存储在 htdocs 文件夹中。

Form.html

<!DOCTYPE html>
<html style=" border-bottom-right-radius: 258px; border-bottom-left-radius: 258px; border-top-left-radius: 258px; border-top-right-radius: 258px; ">
<head>



<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../dist/jquery.validate.js" type="text/javascript"></script>
<link href="../css/ui-lightness/jquery-ui-1.10.4.css" rel="stylesheet">
<script src="../js/jquery-ui-1.10.4.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">


<script type="text/javascript">
$(document).ready(function() {

    $("#form").validate({


        messages:
         {
            ProjectName: {
                required: 'Please Enter Project Name'
            },
            location: {
                required: 'Please Enter Location'
            },
            arch: {
                required: 'Please Enter Architect Name'
            },
            projectno: {
                required: 'Please Enter Project No.'
            },
            dof: {
                required: 'Please Select Date'
            },
            dorder: {
                required: 'Please select Order No.'
            },

            email:{
                required: 'Please write EmailID'
            }
        }
    });

    $( "#datepicker" ).datepicker();

     $("input").focus(function(){
    $(this).css("background-color","#F7D9BA");
  });
  $("input").blur(function(){
    $(this).css("background-color","#B8860B");
  });



  $( "input[type=submit], a, button" )
      .button()
      .click(function( event ) {
        event.Default();
      });

      $( "input[type=reset], a, button" )
      .button()
      .click(function( event ) {
        event.Default();
      });


      $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });

});
</script>
 <style>
 body
 {
  background-color: #CC6600;
 }
span
{
  color:red;
}
.error
{
font-size: 12px;
color: #A72727;
}

label
{
display: inline-block; width: 15em;
}
fieldset div
{
margin-bottom: 1em;
}
fieldset .help
{
display: inline-block;
}
.ui-tooltip
{
width: 210px;
}
input
{
    background-color: white;
    background: white url("../test/inputbox.jpg") repeat-x left top;
    border: 0px solid #ccc;
    padding: 0px 2px;
    height: 25px;

    font: 80% "Trebuchet MS", Trebuchet, Tahoma, Verdana, Arial, sans-serif;
}


 </style>


</head>
<body>
    <h1 style="margin-left: 0px; color:white; margin-left: 600px; "><b><u>Form:</u></b></h1>
<form  id="form">
    <fieldset style=" border-color: ghostwhite; border-width: 12px; margin-top: 42px;; background-color:gray;">
        <legend style=" text-align: center; color:white;">Enter Details</legend>

        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;" >Project:<span>*</span></label>
            <input  name="ProjectName" data-rule-required="true"/>
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Location:<span>*</span> </label>
            <input id="location" name="location" data-rule-required="true" />
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Architect:<span>*</span></label>
            <input name="arch" data-rule-required="true"/>
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Project No.:<span>*</span> </label>
            <input id="projectno" name="projectno" data-rule-required="true" />
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Date:<span>*</span></label>
            <input  type="text" id="datepicker" name="dof" data-rule-required="true" />
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Recent Work:</label>
            <input id="check" type="checkbox" name="check" data-rule-required="fasle" />
        </p>
        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Display Order:<span>*</span></label>
            <select id="dorder" name="dorder" data-rule-required="true" style=" height: 22px; width: 38px; ">
                     <option ></option>
              <option >1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>


                   </select>
        </p>

        <p>

            <label style=" margin-left: 476px; color: whiteSmoke;">Email:<span>*</span></label>
            <input id="email" name="email" data-rule-required="true"/>
        </p>
        <br>
        <p>
            <input style="margin-left:580px; padding-top: 2px;" class="submit" type="submit" value="Submit"/>
             <input style="margin-left:20px; padding-top: 2px;" type="reset" value="Reset" name="Reset" />
        </p>

    </fieldset>
</form>


</body>
</html>

insert.php

<!DOCTYPE html>
<html>
<body>

<?php




$con=mysqli_connect("localhost","root","","NProject");
$rec_limit = 3;
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$Project = mysqli_real_escape_string($con, $_POST['ProjectNo']);
$Location = mysqli_real_escape_string($con, $_POST['Location']);
$Architect = mysqli_real_escape_string($con, $_POST['Architect']);
$ProjectNo = mysqli_real_escape_string($con, $_POST['ProjectNo']);
$Date = mysqli_real_escape_string($con, $_POST['Date']);
$RecentWork = mysqli_real_escape_string($con, $_POST['RecentWork']);
$DisplayOrder = mysqli_real_escape_string($con, $_POST['DisplayOrder']);
$EmailID = mysqli_real_escape_string($con, $_POST['EmailID']);

$sql="INSERT INTO projecttb (Project, Location, Architect, ProjectNo, Date, RecentWork, DisplayOrder, EmailID)
VALUES ('$Project', '$Location', '$Architect','$ProjectNo','$Date','$RecentWork','$DisplayOrder','$EmailID')";

if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?> 

</body>
</html>

1 个答案:

答案 0 :(得分:4)

您需要将此代码添加到表单

<form  id="form" method="post" action="insert.php">

这将调用PHP文件