我有用于将数据插入我的数据库的代码,它正常工作,我试图使它适应现在更新mysql行butitdoes不起作用。这是我的标题
<script type='text/javascript'>
function Bet_game(id)
{
var result = confirm ("Do you want to update your bet?");
if (result)
{
bet_games(id);
}
}
function bet_games(id)
{
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText !="")
{
alert (xmlhttp.responseText);
document.getElementById(id).style.display="none";
return true;
}
}
}
gid = id.replace('tbl_','');
ML_team = document.getElementById('ML_team'+gid).value;
ML_points = document.getElementById('ML_points'+gid).value;
OU_team = document.getElementById('OU_team'+gid).value;
OU_points = document.getElementById('OU_points'+gid).value;
SPREAD_team = document.getElementById('SPREAD_team'+gid).value;
SPREAD_points = document.getElementById('SPREAD_points'+gid).value;
val = "&ML_team="+ML_team+"&ML_points="+ML_points;
val = val + "&OU_team="+OU_team+"&OU_points="+OU_points;
val = val + "&SPREAD_team="+SPREAD_team+"&SPREAD_points="+SPREAD_points;
xmlhttp.open("get","update_bet.php?gid="+ gid + val,true);
xmlhttp.send();
}
</script>
我的表
<?php
foreach ($conn->query("SELECT * FROM game_data INNER JOIN user_betting ON game_data.id=user_betting.game_id WHERE game_data.sport='MLB Baseball' AND user_betting.handicapper_id=2 AND date >= DATE_ADD(NOW(), INTERVAL 2 HOUR) ORDER BY date ASC") as $MLB) { ?>
<form id="<?php echo $MLB['id']; ?>" action="update_bet.php" method="post"><table class="table table-bordered" id="tbl_<?php echo $MLB['id'];?>">';
<thead>
<tr>
<th width="5%" class="head0">Rotation</th>
<th width="50%" class="head1">Team</th>
<th width="10%" class="head0">Money Line</th>
<th width="10%" class="head0">Over/Under</th>
</tr>
</thead>
<tr>
<td colspan="6">
<?php $date = date_create($MLB['date']);
echo date_format($date, 'l F jS Y \@ g:iA'); ?>
</td>
</tr>
<tr>
<td><?php echo $MLB['awayrotation']; ?></td>
<td><?php echo $MLB['awayteam'];?> </td>
<td><?php echo $MLB['awaymoneyline'];?></td>
<td><?php echo $MLB['total'];?></td>
</tr>
<tr>
<td><?php echo $MLB['homerotation'];?></td>
<td><?php echo $MLB['hometeam'];?></td>
<td><?php echo $MLB['homemoneyline'];?></td>
<td><?php echo $MLB['total'];?></td>
</tr>
<tr>
<td colspan="5"><div style="width:100%"><form method="post" name="tbl_<?php echo $MLB['id']; ?>" id="tbl_<?php echo $MLB['id']; ?>" action="update_bet.php"><div align="left" style="width:25%;float:left">Place your bet:</div> <div align="right" style="width:75%;float:right;">
Money Line:
<select name="ML_team<?php echo $MLB['id']; ?>">
<option value=""></option>
<option value="<?php echo $MLB['awayteam'];?>" <?php if($MLB['awayteam'] == $MLB['ML_team']){ echo " selected"; }; ?>><?php echo $MLB['awayteam'];?> </option>
<option value="<?php echo $MLB['hometeam'];?>" <?php if($MLB['hometeam'] == $MLB['ML_team']){ echo " selected"; }; ?>><?php echo $MLB['hometeam'];?> </option>
</select>
<select name="ML_points<?php echo $MLB['id']; ?>">
<option value=""></option>
<option value="1" <?php if ($MLB['ML_points'] == '1') { echo " selected"; }; ?>>1</option>
<option value="2" <?php if ($MLB['ML_points'] == '2') { echo " selected"; }; ?>>2</option>
<option value="3" <?php if ($MLB['ML_points'] == '3') { echo " selected"; }; ?>>3</option>
<option value="4" <?php if ($MLB['ML_points'] == '4') { echo " selected"; }; ?>>4</option>
<option value="5" <?php if ($MLB['ML_points'] == '5') { echo " selected"; }; ?>>5</option>
</select>
<span style="padding-left:10px">Over/Under: </span>
<select name="OU_team<?php echo $MLB['id']; ?>">
<option value=""></option>
<option value="over" <?php if ($MLB['OU_team'] == 'over') { echo " selected"; }; ?> >Over</option>
<option value="under" <?php if ($MLB['OU_team'] == 'under') { echo " selected"; }; ?>>Under</option>
</select>
<select name="OU_points<?php echo $MLB['id']; ?>">
<option value""></option>
<option value="1" <?php if ($MLB['OU_points'] == '1') { echo " selected"; }; ?>>1</option>
<option value="2" <?php if ($MLB['OU_points'] == '2') { echo " selected"; }; ?>>2</option>
<option value="3" <?php if ($MLB['OU_points'] == '3') { echo " selected"; }; ?>>3</option>
<option value="4" <?php if ($MLB['OU_points'] == '4') { echo " selected"; }; ?>>4</option>
<option value="5" <?php if ($MLB['OU_points'] == '5') { echo " selected"; }; ?>>5</option>
</select>
<select hidden="true" id="SPREAD_team<?php echo $MLB['id']; ?>">
<option value=""></option>
</select>
<select hidden="true" id="SPREAD_points<?php echo $MLB['id']; ?>">
<option value="0">0</option>
</select>
<input type="hidden" name="game_id" value="<?php echo $MLB['id'];?>">
<input type="hidden" name="handicapper_id" value="<?php echo $userid; ?>">
<input type="hidden" name="sport" value="<?php echo $MLB['sport'];?>">
<input type="hidden" name="action" value="bet">
<span style="padding-left:5px;">
<input type="button" onClick="Bet_game('tbl_<?php echo $MLB['id'] ?>')" value="Update Bid"></span>
</form>
<form action="actions.php" method="post">
<input type="button" onClick="delete_bet( ' <?php echo $MLB['game_id']; ?> ' , ' <?php echo $MLB['handicapper_id']; ?> ' )" value="Cancel Bid"></input>
</form>
</div></div>
</td>
</tr>
</table>
<?php } ?>
我的update_bet.php
<?php
include 'header.php';
//
$gid = $_REQUEST['gid'];
//
$ML_team=$_REQUEST['ML_team'];
$ML_points=$_REQUEST['ML_points'];
$OU_team=$_REQUEST['OU_team'];
$OU_points=$_REQUEST['OU_points'];
$SPREAD_team=$_REQUEST['SPREAD_team'];
$SPREAD_points=$_REQUEST['SPREAD_points'];
//
$user_id= $_SESSION['user']['id'];
//
//$sql = "SELECT * FROM game_data WHERE id='$gid'";
//$games = mysql_query($sql);
//while($game = mysql_fetch_assoc($games))
//{
// $id = $game['id'];
// $sport = $game['sport'];
// $dt=date('Y-m-d H:s:i');
//}
$sql="UPDATE user_betting SET (ML_team, ML_decision, ML_points, OU_team, OU_decision, OU_points, SPREAD_team, SPREAD_decision, SPREAD_points)
values ('$ML_team','','$ML_points','$OU_team','','$OU_points','$SPREAD_team','','$SPREAD_points') WHERE handicapper_id='".$user_id."' AND game_id='".$gid."'";
//
$games = mysql_query($sql) or die("Record no updated".mysql_error());
echo "Record save successfully";
?>
我错过了什么?
答案 0 :(得分:0)
尝试在Google Dev Tools Inspector中检查网络响应。如果您获得500,则脚本会出现语法错误。如果您看到“记录保存成功”消息,请尝试打开脚本顶部的ini_set('display_errors',1);
以查看是否缺少任何变量,或者回显您的查询并检查开发工具,然后尝试直接在mysql上查询。另请注意,您应该转义变量以确保安全性或使用mysqli预处理语句。