php - Getting 0 as a value sending to my database during an AJAX call form submission -


i trying send user id , value 'approved' through ajax call prepared statement send database. of right getting id part of correctly. however, value approved part sending , updating database 0.

does see why?

my form

$con = mysqli_connect("localhost", "root", "", "db"); $run = mysqli_query($con,"select * user_requests order id desc"); $numrows = mysqli_num_rows($run);      if( $numrows ) {         while($row = mysqli_fetch_assoc($run)){             if($row['status'] == "pending"){                  $pending_id        = $row['id'];                 $pending_user_id   = $row['user_id'];                 $pending_firstname = $row['firstname'];                 $pending_lastname  = $row['lastname'];                 $pending_username  = $row['username']; ?>         <form action="" method="post" id="status">              <input type='hidden' name='id' value='<?php echo $pending_id; ?>' id='pending_id'/> <?php         if ($pending_firstname == true) {             echo "name - ". $pending_firstname . " " . $pending_lastname . "</br>" .                  "username - ". $pending_username . "</br></br>"                 //echo print_r($_post); ?>                           <button class="approve" type="submit" form="status" name="approve" value="<?=$pending_id;?>">approve</button>                         <button class="deny" type="submit" form="status" name="deny" value="<?=$pending_id;?>">deny</button>                         </form><br><br><br> 

my ajax call

$(document).ready(function () {      $('.approve').click(function () {         $.ajax({             url: 'userrequest_approve.php',             type: 'post',             data: {                 id: $(this).val(), //id                 status: 'approved' //status             },             success: function (data) {                 //do data got returned                 $("#success").fadein();                 $("#success").show();                 $('#success').html('user status changed!');                 $('#success').delay(5000).fadeout(400);             },             //type: 'post'         });         return false;     }); }); 

my prepared statement

$pending_id = $_post['id']; $status = $_post['status'];  $con = mysqli_connect("localhost", "root", "", "db");     /* check connection */     if (mysqli_connect_errno()) {         printf("connect failed: %s\n", mysqli_connect_error());         exit();     }     $stmt = $con->prepare("update user_requests set status=?, date_responded=now() id=?");     if ( false===$stmt ) {      // check errors prepare         die('user request update prepare() failed: ' . htmlspecialchars($con->error));     }     $stmt->bind_param('ii', $status, $pending_id);     // comment added php-dev : should false === $stmt->bind_param ...      if ( false===$stmt ) {     // check errors binding parameters         die('user request update bind_param() failed: ' . htmlspecialchars($stmt->error));     }     $stmt->execute();     // comment added php-dev : should false === $stmt->execute ...      if ( false===$stmt ) {         die('user status update execute() failed: ' . htmlspecialchars($stmt->error));     }   

by ajax form providing "status" string value "approved" server while assuming integer in binding. change "status" in ajax code '1'


Comments