0

EDITED with UPDATED CODE: Im missing something here; the jQuery is working, but the variables arent passing to the query. Below is all of the updated code:

<span class="accepted"><a href="#" class="accept" id="<?php echo $id1; ?>" data-order="<?php echo $name; ?>"><input type="button" title="accept" value="Accept" /></a></span>

AJAX Script

<script type="text/javascript">
$(function() {
$(".accept").click(function(){
var element = $(this);
var del_id = element.attr("id");
var order_id = element.attr("data-order");

//if(confirm("Are you sure you want to delete this?"))
//{

     $.ajax({
       type: "POST",
       url: "accept.php",
       //data: info,
       data: {id:del_id,order_id:order_id},
       success: function(){}
    //
    });
      $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
      .animate({ opacity: "hide" }, "slow");
     //}
    //return false;
    });
    });
    </script>

new php file

include('db.php');
$id = $_POST['id'] ;
$name = $_POST['order_id'] ;
$sql = "UPDATE mgap_orders SET mgap_status = 1 WHERE mgap_ska_id = :id AND mgap_ska_report_category = :name"; 
$stmt = $pdo->prepare($sql); 

$stmt->execute(array(
':id' => '$id',
':name' => '$name'
));

5 Answers 5

5

Instead of using var info = 'id=' + del_id; and data: info, You should send variables like below:

data: {id:del_id}

Future more, if you want to pass more variables you can go like below:

data: {id:del_id,order:ORDER_ID}

Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

That does help; thanks. Now I just need to know how to add the second variable to the href.
@TechnoCripple you can use custom attribute on a link
Use <a href="#" class="accept" id="<?php echo $id1; ?>" data-name="<?php echo $order_name; ?>"> and retrieve it using var order_id = element.attr("data-name"); then pass it:- data: {id:del_id,order: order_id}
1

do like this

$.ajax({
   type: "POST",
   url: "delete.php",
   data: {id:del_id,order:order_variable},
   success: function(){
 }

4 Comments

Thanks for the input; I understand how to add both to the AJAX by your example. How would I add the second variable to the href? <span class="accepted"><a href="#" class="accept" id="<?php echo $id1; ?>"><input type="button" title="accept" value="Accept" /></a></span>
try like this herf="example.php?var=value1&var2=value2" for passing two url params.By the way in your example there is no params passed.
ok I have updated all of my code based on the input everyone has given (thanks), but my query is not working. Im missing something in the incorporation of the variables. Please have a look; I greatly appreciate your help.
@TechnoCripple you have errors in php code.change you query to UPDATE mgap_orders SET mgap_status = '1' WHERE mgap_ska_id = '".$id."' AND mgap_ska_report_category = '".$name."'
0

Specify your Data as an object. Should be separated by comma for each variable.

data: {variablename1: value1, variablename2: value2}

So you code should look like:

<script type="text/javascript">
$(function() {
$(".delete").click(function(){
var element = $(this);
var del_id = element.attr("id");
//var info = 'id=' + del_id;
if(confirm("Are you sure you want to delete this?"))
{
 $.ajax({
   type: "POST",
   url: "delete.php",
   data: { id: del_id, var2: var2, var3: var3 },
   success: function(){
 }
});
  $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
  .animate({ opacity: "hide" }, "slow");
 }
return false;
});
});
</script>

Comments

0
<script type="text/javascript">
$(function() {
$(".delete").click(function(){
var element = $(this);
var del_id = element.attr("data-id");
var order_id = element.attr("data-order");
var info = 'id=' + del_id;
var order = 'order' + order_id;
if(confirm("Are you sure you want to delete this?"))
{
 $.ajax({
   type: "POST",
   url: "mod_accept.php", //Changed the processor file
   data: {info, order},
   success: function(){
 }
});
  $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
  .animate({ opacity: "hide" }, "slow");
 }
return false;
});
});
</script>

Then in your html:

<span class="accepted"><a href="#" class="accept" data-id="<?php echo $id1; ?>" data-order="<?php echo $someVariable ?>"><input type="button" title="accept" value="Accept" /></a></span>

2 Comments

@TechnoCripple accept it as the right answer. Thank you.
Krishna actually corrected the errors in the updated code; thanks for your help.
0

do something like

    <span class="accepted">
          <a href="#" class="delete" id="<?php echo $id1; ?>" 
data-order="<?php echo $order_id;?>">
<input type="button" title="accept" value="Accept" /></a>
      </span>


<script type="text/javascript">
$(function() {
    $(".delete").click(function(){
    var element = $(this);
    var del_id = element.attr("id");
    var order_id = element.attr("data-order");
    if(confirm("Are you sure you want to delete this?"))
    {
     $.ajax({
       type: "POST",
       url: "delete.php",
       data: {id:del_id,order_id:order_id},
       success: function(){
     }
    });
      $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
      .animate({ opacity: "hide" }, "slow");
     }
    return false;
    });
});
</script>

1 Comment

Code has been updated in my original post. My query isnt receiving the variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.