单击提交时,某些文本框变为空白

时间:2013-07-18 07:51:33

标签: php html mysql

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

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

我知道为什么它会说“string(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'银行详细信息到银行数据库”下面:

<?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());
    }
}
?>

2 个答案:

答案 0 :(得分:0)

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

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

在模糊事件中,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(''); 
                });
            });
在您的代码中

并检查值是否已插入。

答案 1 :(得分:0)

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

例如:

$TruckDamagePost    = $TruckDamage;

这应该改为:

$TruckDamagePost    = $_POST['TruckDamage'];

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

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

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

我无法判断它是否会使您的代码按照您的意愿运行,但这肯定是首先需要纠正的。