php - Update MySQL table with button without refreshing page using ajax -


i trying update value in database without refreshing page using ajax. new ajax have have managed create function after searching answers on stackoverflow unable make work.

one main page...

<script type="text/javascript" src="/js/jquery.js"></script> <script>   function updaterecord(id)   {       jquery.ajax({        type: "post",        url: "del_reason.php",        data: 'id='+id,        cache: false,        success: function(response)        {          alert("record updated");        }      });  } </script> 

the button (which in form)

<input type="button" name="delete_pos" value="delete" class="delrow_pos"        onclick="updaterecord(<? echo $row['reasonid']; ?>);"/> 

the contents of del_reason.php

$var = @$_post['id'] ; $sql = "update gradereason set current = 0 reasonid = $var"; $result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli)); //added testing echo 'var = '.$var; 

the database connection ok because other functions on same page connecting database work fine , other jquery functions when button clicked alert says record upodated isn't

the mysql query on del_reason.php failed because needed it's own mysqli connection database.

as added script worked


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -