0

在我的网页上,当您点击提交提交表单时,点击提交后,几个文本框突然变为空白,因此数据无法输入数据库。我得到这个错误出现:

string(0) "" 不正确的整数值:第 1 行的列 'TotalProfit' 的''

我知道为什么它说“字符串(0)”“”,那是因为它正在转储变量 $TruckDamagePost 但因为文本框变为空白,它试图将其提交为空白。

变为空白的文本框是:总利润滞纳金罚款-成本旅行-费用燃料成本卡车损坏货物损坏

这是我的网页HTML 代码

<head>

    <!-- Appears in the title bar in web browser -->
    <title>JWT Haulage Group Drivers Area</title>

    <meta name="description" content="JWT Haulage Group Ltd is a virtual trucking company for Euro Truck Simulator 2, UK and 
    German Truck Simulator. We have over 600 drivers registered already.">                            <!-- Meta Stuff Required -->

    <meta name="keywords" content="JWT, JWT Haulage, JWT Haulage Group, JWT Haulage Ltd, Euro Truck Simulator 2, ETS2, 
    UK Truck Simulator, UKTS, German Truck Simulator, GTS, Virtual Trucking Company, VTC">

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />                             <!-- Meta Stuff Required -->

    <link rel="stylesheet" type="text/css" href="styles.css" />                                       <!-- CSS -->

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>               <!-- JQuery -->

    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-37114333-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>

    <script>
     $(function() {
    if(!$.support.placeholder) { 
        var active = document.activeElement;
        $(':text').focus(function () {
            if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
                $(this).val('').removeClass('hasPlaceholder');
            }
        }).blur(function () {
            if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
                $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
            }
        });
        $(':text').blur();
        $(active).focus();
        $('form').submit(function () {
            $(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
        });
    }
});
    </script>

    <script>
    var error = "";
    error = "<?=$error?>";
    var spError = error.split("|");
    for(var i=0; i<spError.length;i++){
        $('.jwtinternational-application').append("<p class='error'>"+spError[i]+"<br/></p>");
        //alert(spError[i]);
    }   
    </script>

    <SCRIPT language=Javascript>
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       //-->

    </SCRIPT>

</head>

<h4>JWT Log Form</h4>
<h4>WARNING: do not use the below form as it is currently being worked on</h4>
 The following form can be used to log your loads for JWT in ETS2.<br>
 If one of the fields do not apply to your load just put £0 or N/A.<br>
<form name="jwtinternational-application-form" class='jwtinternational-application-form' action="drivers-log-send.php" method="post">
    <div class='jwtinternational-application-left'>
        <input type="text" class="text-box" name="forum-name" placeholder="Registered Forum Name"/><br>
        <input type="text" class="text-box" name="driver-number" placeholder="Driver Number"/><br>
        <input type="text" class="text-box" name="email-address" placeholder="Email Address"/><br>
        <div>
             What division in ETS2 are you driving for?<br>
            <select id="dropdown1" name="dropdown1" class="text-box">
                <option value="">Please Select....</option>
                <option value="International">International</option>
                <option value="Samcro">Samcro Transport</option>
                <option value="Port">Port Logistics</option>
                <option value="Bio">Bio-Fuels</option>
                <option value="WnD">Wagon 'n' Drag</option>
            </select>
            <br>
        </div>
        <input type="text" class="text-box" name="truck-driving" placeholder="Truck Driving"/><br>
        <input type="text" class="text-box" name="cargo" placeholder="Cargo"/><br>
        <br>
        <input type="text" class="text-box" name="depot-leaving" placeholder="Depot Leaving"/><br>
        <input type="text" class="text-box" name="city-leaving" placeholder="City Leaving"/><br>
        <input type="text" class="text-box" name="country-start" placeholder="Country Starting In"/><br>
        <div>
             Day Start:<br>
            <select id="dropdown2" name="dropdown2" class="text-box">
                <option value="">Please Select....</option>
                <option value="Monday">Monday</option>
                <option value="Tuesday">Tuesday</option>
                <option value="Wednesday">Wednesday</option>
                <option value="Thursday">Thursday</option>
                <option value="Friday">Friday</option>
                <option value="Saturday">Saturday</option>
                <option value="Sunday">Sunday</option>
            </select>
            <br>
        </div>
        <div>
             Time Start:<br>
            <input type="time" class="text-box" name="time-start"/><br>
        </div>
        <input type="text" class="text-box" name="mileage-start" placeholder="Mileage Start" onkeypress="return isNumberKey(event)"/><br>
        <br>
        <input type="text" class="text-box" name="depot-arriving" placeholder="Depot Arriving"/><br>
        <input type="text" class="text-box" name="city-arriving" placeholder="City Arriving"/><br>
        <input type="text" class="text-box" name="country-end" placeholder="Country Finishing In"/><br>
        <div>
             Day End:<br>
            <select id="dropdown3" name="dropdown3" class="text-box">
                <option value="">Please Select....</option>
                <option value="Monday">Monday</option>
                <option value="Tuesday">Tuesday</option>
                <option value="Wednesday">Wednesday</option>
                <option value="Thursday">Thursday</option>
                <option value="Friday">Friday</option>
                <option value="Saturday">Saturday</option>
                <option value="Sunday">Sunday</option>
            </select>
            <br>
        </div>
        <div>
             Time End:<br>
            <input type="time" class="text-box" name="time-end" placeholder="Time End"/><br>
        </div>
        <input type="text" class="text-box" name="mileage-end" placeholder="Mileage End" onkeypress="return isNumberKey(event)"/><br>
        <div>
             Cargo Damage:<br>
             &pound;&nbsp;<input type="text" class="text-box" name="cargo-damage" onkeypress="return isNumberKey(event)"/><br>
        </div>
        <div>
             Truck Damage:<br>
             &pound;&nbsp;<input type="text" class="text-box" name="truck-damage" onkeypress="return isNumberKey(event)"/><br>
        </div>
        <div>
             Fuel Cost:<br>
             &pound;&nbsp;<input type="text" class="text-box" name="fuel-cost" onkeypress="return isNumberKey(event)"/><br>
            <br>
        </div>
        <input type="text" class="text-box" name="fuel-amount" placeholder="Fuel Amount (Litres)" onkeypress="return isNumberKey(event)"/><br>
        <div>
             Travel Expenses (Ferry,Toll,Channel Tunnel):<br>
             &pound;&nbsp;<input type="text" class="text-box" name="travel-expenses" onkeypress="return isNumberKey(event)"/><br>
        </div>
        <div>
             Total Cost of Fines:<br>
             &pound;&nbsp;<input type="text" class="text-box" name="fines-cost" onkeypress="return isNumberKey(event)"/><br>
            <br>
        </div>
        <input type="text" class="text-box" name="on-time-or-late" placeholder="On Time/Late"/><br>
        <div>
             Late Fee:<br>
             &pound;&nbsp;<input type="text" class="text-box" name="late-fee" onkeypress="return isNumberKey(event)"/><br>
        </div>
        <div>
             Total Profit:<br>

这是我的PHP 代码,它将整个表单发送到电子邮件地址,并将文本框中的数据发送到数据库中,这些数据变为空白。该数据位于“///PHP TO INSERT DRIVER'S BANK DETAILS INTO BANK DATABASE”下方:

<?php
///PHP TO INSERT DRIVER'S BANK DETAILS INTO BANK DATABASE
session_start();
$host     = ""; // Host name
$username = ""; // Mysql username
$password = ""; // Mysql password
$db_name  = ""; // Database name
$tbl_name = "jwtdriversbank"; // Table name
$un       = "";
$usrname  = "";
$usrpass  = "";
$userID   = "";
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
if (isset($_SESSION['usrName'])) {
    $usrname = $_SESSION['usrName'];
} else {
    echo "4";
}
//var_dump ($usrname);
if (isset($_SESSION['usrPass'])) {
    $usrpass = $_SESSION['usrPass'];
} else {
    echo "5";
}
$sql    = "SELECT * FROM jwtdrivers WHERE username='$usrname' and password='$usrpass'";
$result = mysql_query($sql);
$rows   = mysql_fetch_array($result);
$userID = $rows['id'];
//var_dump ($userID);
if ($userID == "") {
    echo "3";
} else {
    $TotalProfitPost    = $TotalProfit;
    $LateFeePost        = $LateFee;
    $FinesCostPost      = $FinesCost;
    $TravelExpensesPost = $TravelExpenses;
    $FuelCostPost       = $FuelCost;
    $CargoDamagePost    = $CargoDamage;
    $TruckDamagePost    = $TruckDamage;
    var_dump($TruckDamagePost);
    $sql    = "INSERT INTO $tbl_name (DriverID, TotalProfit, LateFee, FinesCost, TravelExpenses, FuelCost, CargoDamage, TruckDamage)VALUES('$userID','$TotalProfitPost','$LateFeePost','$FinesCostPost','$TravelExpensesPost','$FuelCostPost','$CargoDamagePost',
            '$TruckDamagePost')";
    $result = mysql_query($sql);
    if ($result) {
    } else {
        die(mysql_error());
    }
}
?>
4

2 回答 2

0

我认为在提交表单时,hasPlaceholder该类正在被应用。因此,在提交表单时,值会变空。

        $('form').submit(function () {
            $(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
        });

在 blur 事件中,hasPlaceholder将应用于文本框。因此,在提交表单时,带有类的输入hasPlaceholder正在清空该值。因此,在提交表单时,不会在服务器端获得值。

.blur(function () {
            if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
                $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
            }
        });

更新: 尝试更换

        $('form').submit(function () {
            $(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
        });

          $('form').submit(function () {
                $(this).find('.hasPlaceholder').each(function() {
                    //$(this).val(''); 
                });
            });

在您的代码中并检查是否插入了值。

于 2013-07-18T07:59:09.093 回答
0

首先 - 您根本不访问 php 中的 POST/GET 数据。

例如:

$TruckDamagePost    = $TruckDamage;

这应该改为:

$TruckDamagePost    = $_POST['TruckDamage'];

第二个问题是您在 HTML 中使用的名称与 php.ini 中的变量不同。对于上述变量,您有以下 HTML:

<input .... name="truck-damage" .... />

您必须将您的 HTML 更改为<input .... name="TruckDamage" .... />或修改您的 php 代码$TruckDamagePost = $_POST['truck-damage'];(当然您必须检查所有表单/php 代码,而不仅仅是TruckDamage字段/变量)

我不知道它是否会让你的代码按你的意愿工作,但当然这是必须首先纠正的事情。

于 2013-07-18T09:35:30.550 回答