我有一个HTML表,其中包含从数据库中检索的数据。 该表的一个字段由ajax内联编辑更新。 除输入验证外,一切都很好。
这是jQuery代码:
jQuery(document).ready(function() {
jQuery(".edit_tr").click(function() {
var ID = jQuery(this).attr('id');
jQuery("#first_" + ID).hide();
jQuery("#first_input_" + ID).show();
}).change(function() {
var ID = jQuery(this).attr('id');
var first = jQuery("#first_input_" + ID).val();
var dataString = 'id=' + ID + '&lottery=' + first;
jQuery("#first_" + ID).html('<img src="images/loading.gif" />');
jQuery(".editbox").each(function() {
blottery = jQuery(this).val();
if ((first.length > 0) && (blottery < 90))
{
jQuery.ajax({
type: "POST",
url: "scripts/table_edit.php",
data: dataString,
cache: false,
success: function(html) {
jQuery("#first_" + ID).html(first);
}
});
} else {
alert('Errore');
}
});
});
jQuery(".editbox").mouseup(function() {
return false
});
jQuery(document).mouseup(function() {
jQuery(".editbox").hide();
jQuery(".text").show();
});
});
这是PHP代码:
<?php
mysql_select_db($database_config, $config);
$query_viewteamcoach = "SELECT f_player.id, f_player.playerName, f_player.playerOverall, f_player.playerPosition, f_player.playerLottery FROM f_player ORDER BY f_player.playerOverall DESC";
$viewteamcoach = mysql_query($query_viewteamcoach, $config) or die(mysql_error());
$row_viewteamcoach = mysql_fetch_assoc($viewteamcoach);
$totalRows_viewteamcoach = mysql_num_rows($viewteamcoach);?>
<table class="dataTable" style="white-space: nowrap">
<tr class="title">
<th rowspan="1" colspan="1" class="first-head">
Nome
</th>
<th rowspan="1" colspan="1" class="head">
Posizione
</th>
<th rowspan="1" colspan="1" class="head">
Overall
</th>
<th rowspan="1" colspan="1" class="head">
Lotto
</th>
</tr>
<?php do {
$id=$row_viewteamcoach['id'];
$lottery=$row_viewteamcoach['playerLottery'];?>
<tr id="<?php echo $id; ?>
" class="edit_tr">
<td class="table0">
<?php echo $row_viewteamcoach['playerName'];?>
</td>
<td class="table1">
<?php echo $row_viewteamcoach['playerPosition'];?>
</td>
<td class="table1">
<span class="labelov"><?php echo $row_viewteamcoach['playerOverall']; ?>
</span>
</td>
<td class="table1">
<span id="first_<?php echo $id;?>" class="text"><?php echo $lottery; ?>
</span>
<input size="1" maxlength="2" type="text" value="<?php echo $lottery;?>" class="editbox" id="first_input_<?php echo $id; ?>
"/><img style="cursor:pointer" src="images/inline_edit.png" width="15" height="15"/>
</td>
</tr>
<?php } while ($row_viewteamcoach = mysql_fetch_assoc($viewteamcoach)); ?>
</table>
table_edit.php
if($_POST['id'])
{$id=mysql_escape_String($_POST['id']);
$lottery=mysql_escape_String($_POST['lottery']);
$sql = "update f_player set playerLottery='$lottery' where id='$id'";
mysql_query($sql);}
问题在于输入文本验证;如果我插入一个大于90的数字,则会显示错误,但更新成功完全相同。
我该如何解决这个问题?