I am trying to execute some php code that will update my database. Though, I can't seem to get it to work. I tried using a form but I don't want to redirect as I would have to pass variables to the seperate page. What I have now is a button calling javascript which then calls another php functions but then it doesn't let me do anything else. Any suggestions would be helpful
 <script>
  function result(){
alert("<?php uresult(); ?>");
 }
function uresult(){
  //echo ("<script>console.log('in function')</script>");
if (isset($_POST['submit']) ) { 
  if(!empty( $_POST['comments'] ) ) {
     $update_query = "Update ". $Main_Trainees_Tbl. " ".
                  " Set enabled='$enabled' , comments='$comments', ".
          " comments_date='$date' ".
          " Where email = '$email' ";
    $update_result = mysql_query($update_query) or die(mysql_error());
    header('Location: uteptrainee_data.php');
    exit;
} 
}
 }//end exec
   mysql_close($conn);
  //header('Location: uteptrainee_data.php');
  //exit;  
?>
 <button  onclick="result()" name = "submit" >Update</button>
</html>
 
     
    