gpt4 book ai didi

php - 单击提交时,某些文本框会变成空白

转载 作者:行者123 更新时间:2023-11-30 01:28:40 25 4
gpt4 key购买 nike

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

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

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

变为空白的文本框是:利润总额滞纳金罚款成本差旅费燃料成本卡车损坏 cargo 损坏

这是我的网页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());
}
}
?>

最佳答案

我认为提交表单时,会应用 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('');
});
});

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

关于php - 单击提交时,某些文本框会变成空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17717691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com