0

我这里有一个在数据库中插入数据的代码,它可以工作并且没有错误,但是当我将我的 jquery 代码用于验证数据时,我用于将数据插入数据库的 php 代码不起作用,可以请检查我的代码。谢谢!

这是我的php代码:index.php

<form id="FormToValidate" action="insert.php" method="POST">
  <div id="content">
    <p>
      <input type="text" name="csname" id="csname" style="width:250px" margin-bottom="3px"/>
         </p>
        <p>
          <select name="units" style="width:254px">
            <option value="option">option</option>
           </option>
            <option value="option">option</option>
</option>

          </select>
        </p>
        <p>
          <input type="text" name="color" id="color" style="width:250px"/>
        </p>


      <p>
        <input type="text" name="consticker" id="consticker" style="width:250px"/>
      </p>
      <p>
        <select name="mp" style="width:254px">
          <option value="name">name</option>

        </select>
      </p>
        <p>
          <select name="grm" style="width:254px">
            <option value="name">name</option>

          </select>
        </p>
        <p><select name="typeoftransact" style="width:254px">
<option value="type">type</option>

</select></p>
      <p>
        <input name="dp" type="dp" style="width:250px" />
      </p>
      <p>
        <input name="amount" type="amount" style="width:250px" />
      </p>
      <p>
        <input name="dirate" type="dirate" style="width:250px" />
      </p>
      <p align="right">AMNT PAID: </p>
<p>NEXT</p>
</div>

    <div id="secondary">
      <p>VSI No.:</p>
        <p>DATE:</p>
        <p>&nbsp; </p>
      <p>TYPE OF SUBSIDY 1:</p>
        <p>TYPE OF SUBSIDY 2:</p>
        <p>TYPE OF SUBSIDY 3:</p>
        <p>TYPE OF SUBSIDY 4:</p>
        <p>TYPE OF SUBSIDY 5:</p>
        <p>CHATTEL MORTGAGE:</p>
        <p>&nbsp;</p>
        <p>
          <input name="chapaid" type="text" style="width:120px" />
        </p>
</div>
    <div id="third">
      <p>
        <input type="text" name="vsi" id="vsi" style="width:180px"/>
</p>
<p>
  <input type="text" name="date" id="date" style="width:180px"/>
</p>
<p>&nbsp;</p>
<p>
  <select name="type1" style="width:180px">
    <option value="option">option</option>
  </select>
</p>
<p>
  <select name="type2" style="width:180px">
   <option value="option">option</option>
  </select>
</p>
<p>
  <select name="type3" style="width:180px">
    <option value="option">option</option>
  </select>
</p>
<p>
  <select name="type4" style="width:180px">
    <option value="option">option</option>
  </select>
</p>
<p>
  <select name="type5" style="width:180px">
    <option value="option">option</option>
  </select>
</p>
        <p>FREE: 
          <input name="chafree" type="text" style="width:100px" />
        </p>
</div>
<div id="fourth">
        <p>&nbsp;</p>
<p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>Php: 
      <input name="type1amount" type="text" style="width:120px" />
        </p>
        <p>Php:
          <input name="type2amount" type="text" style="width:120px" />
        </p>
        <p>Php:
          <input name="type3amount" type="text" style="width:120px" />
        </p>
        <p>Php:
          <input name="type4amount" type="text" style="width:120px" />
        </p>
        <p>Php:
          <input name="type5amount" type="text" style="width:120px" />
        </p>
    <p>COST: 
      <input name="chacost" type="text" style="width:120px" />
    </p>
        <p>&nbsp;</p>

    <p align="right"><input class="small button blue" name="Save" type="submit" id="Save" value="Save" /></p>


</div>
</div>
</form>

这是我的功能,insert.php

<?php
include("connection.php");

$vsi = $_POST["vsi"];
$date = $_POST["date"];
$custname = $_POST["csname"];
$unit = $_POST["units"];
$color = $_POST["color"];
$consticker = $_POST["consticker"];

$mp = $_POST["mp"];
$grm = $_POST["grm"];
$typetrans = $_POST["typeoftransact"];
$dp = $_POST["dp"];
$amount = $_POST["amount"];
$dirate = $_POST["dirate"];
$typesub1 = $_POST["type1"];
$typesub2 = $_POST["type2"];
$typesub3 = $_POST["type3"];
$typesub4 = $_POST["type4"];
$typesub5 = $_POST["type5"];
$chacost = $_POST["chacost"];
$chapaid = $_POST["chapaid"];
$chafree = $_POST["chafree"];
$type1amount = $_POST["type1amount"];
$type2amount = $_POST["type2amount"];
$type3amount = $_POST["type3amount"];
$type4amount = $_POST["type4amount"];
$type5amount = $_POST["type5amount"];

if($_POST["Save"]=="Save")
{
$query="INSERT INTO accounts (vsi,date,cname,unit,color,consticker,typetrans,downpayment,amountfinanced,dirate,mp,grm,typesub1,typesub2,typesub3,typesub4,typesub5,chapaid,chacost,chafree,type1amount,type2amount,type3amount,type4amount,type5amount)
VALUES
('".$vsi."','".$date."','".$custname."','".$unit."','".$color."','".$consticker."','".$typetrans."','".$dp."','".$amount."','".$dirate."','".$mp."','".$grm."','".$typesub1."','".$typesub2."','".$typesub3."','".$typesub4."','".$typesub5."','".$chapaid."','".$chacost."','".$chafree."','".$type1amount."','".$type2amount."','".$type3amount."','".$type4amount."','".$type5amount."');";

(mysql_query($query))

or die ("error!".mysql_error() );

}

header('Location: index.php');

?>

如果我把这个 jquery 代码,我的 php 代码不起作用,但如果没有,它工作正常,这是我的jquery script

<script src="Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.validate.wrapper.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">

    $(document).ready(function () {
        // 1. prepare the validation rules and messages.
        var rules = {
            vsi: {
                required: true,
                minlength: 7
            },
            date: "required",
            csname: "required",
            color: "required"
        };
        var messages = {
            vsi: {
                required: "VSI Number must be Inputted.",
                minlength: "VSI Number should be atleast 7 numbers."
            },
            date: "Date is requried",
            csname: "Customer Name is required",
             color: "Color is required"
        };

        // 2. Initiate the validator
        var validator
            = new jQueryValidatorWrapper("FormToValidate",
                rules, messages);

        // 3. Set the click event to do the validation
        $("#Save").click(function ()
                     {
                        if (!validator.validate())
                           {
                             return;
                            }
                        $('#FormToValidate').submit();
                         alert("Data Saved!");
                          return;

                    });
    });

</script>
4

1 回答 1

0
<script src="Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.validate.wrapper.js" type="text/javascript"></script>
规则、消息);// 3. 设置点击事件进行验证 $("#Save").click(function () { if (!validator.validate()) { return; } $('#FormToValidate').submit() ; alert("数据已保存!"); return; }); }); alert("数据已保存!"); 返回; }); }); alert("数据已保存!"); 返回; }); });
于 2013-12-09T09:36:50.950 回答