I have code that i use to insert data into my database and it works fine im trying to adapt it to now update the mysql row butitdoes not work. This is my header
<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>
My table
<?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 } ?>
My 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";
?>
what am i missing??
Try checking the network response in Google Dev Tools Inspector. If you're getting a 500 the script has a syntax error. If you are seeing your "Record save success" message, try turning on ini_set('display_errors',1);
at the top of the script to see if any of the variables were missing, or echo your query back and check in Dev Tools, then try that query directly on mysql. Also note you should escape your variables for security or use mysqli prepared statements.