PHP/Ajax not updating mysql -
i have code use insert data database , works fine im trying adapt update mysql row butitdoes not work. header
<script type='text/javascript'> function bet_game(id) { var result = confirm ("do want update 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 * game_data inner join user_betting on game_data.id=user_betting.game_id game_data.sport='mlb baseball' , user_betting.handicapper_id=2 , date >= date_add(now(), interval 2 hour) order date asc") $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 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 * game_data 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') handicapper_id='".$user_id."' , game_id='".$gid."'"; // $games = mysql_query($sql) or die("record no updated".mysql_error()); echo "record save successfully"; ?>
what missing??
try checking network response in google dev tools inspector. if you're getting 500 script has syntax error. if seeing "record save success" message, try turning on ini_set('display_errors',1);
@ top of script see if of variables missing, or echo query , check in dev tools, try query directly on mysql. note should escape variables security or use mysqli prepared statements.
Comments
Post a Comment