i have drag , drop table using change if has made payment. . right drag , drop part works great. however, cannot figure out how give 3 different table columns 'values'.
i have 3 different sections:
owes = 1 partially paid = 2 paid = 3 i have column in database list value , called payment_id.
so, when item dragged 1 column another, want recognized , query sent database update table.
<table class="paymenttable" id="dragtable"> <?php //payment section $con = mysqli_connect("localhost", "", "", ""); $run = mysqli_query($con,"select * payment_status order id desc"); $numrows = mysqli_num_rows($run); if( $numrows > 0) { while($row = mysqli_fetch_assoc($run)){ $payment_id = $row['payment_id']; if($payment_id == 3){ $paid_id = $row['user_id']; $paid_name = $row['firstname']; } if($payment_id == 2){ $partially_paid_id = $row['user_id']; $partially_paid_name = $row['firstname']; $partially_paid_amount = $row['payment_amount']; } if($payment_id == 1){ $owes_id = $row['user_id']; $owes_name = $row['firstname']; } ?> <tr> <th class="thpayment">paid</th> <th class="thpayment">partially paid</th> <th class="thpayment">owes</th> </tr> <tr> <td class="tdpayment" id="paid"> <div> <?php if ($paid_name == true) { echo $paid_name; } else { echo "no 1 has paid"; } ?> </div> </td> <td class="tdpayment" id="partially_paid"> <div> <?php if ($partially_paid__name == true) { echo $partially_paid__name . " - " . $partially_paid_amount; } else { echo "no 1 has made partial payment"; } ?> </div> </td> <td class="tdpayment" id="owes"> <div> <?php if ($owes_name == true) { echo $owes_name; } else { echo "everyone has paid something"; } } } current js make table draggable.
$(function() { $( "#paid, #partially_paid, #owes" ).sortable({ connectwith: ".tdpayment", remove: function(e, ui) { var $this = $(this); var childs = $this.find('div'); if (childs.length === 0) { $this.text("nothing"); } }, receive: function(e, ui) { $(this).contents().filter(function() { return this.nodetype == 3; //node.text_node }).remove(); }, }).disableselection(); }); i know has done ajax, not know how assign these values this.
$(document).ready(function () { $('#update_group').on('submit', function (event) { //do have put table in form? event.preventdefault(); $.ajax({ url: 'update_payment_status.php', type: 'post', //not sure put here drag , drop table data: { paid: $("#paid").val(3), //paid partially_paid: $("#partially_paid").val(2), //partially paid owes: $("#owes").val(1), //owes }, success: function (data) { //do data got returned $(".success").fadein(); $(".success").show(); $('.success').html('payment status changed!'); $('.success').delay(5000).fadeout(400); alert(data); }, error: function(jqxhr, textstatus,errorthrown ) { // alert on http error alert( textstatus + errorthrown ); } }); return false; }); }); this first attempt ajax so, i'm not sure how structure really.
update_payment_status
ini_set('log_errors', 1); ini_set('error_log', __dir__ . directory_separator . 'error.log'); error_reporting(e_all); require_once 'core/init.php'; $owes = $_post['id']; $partially_paid = $_post['firstname']; $owes = $_post['lastname']; $payment_username = $row['username']; $payment_email = $row['email']; $con = mysqli_connect("localhost","","",""); /* check connection */ if (mysqli_connect_errno()) { printf("connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $con->prepare("update payment_status set id=? users_id=?"); if ( !$stmt || $con->error ) { // check errors prepare die('payement status update prepare() failed: ' . htmlspecialchars($con->error)); } if(!$stmt->bind_param('iiii', $change_group, $change_group, $approved_id, $approved_id)) { // check errors binding parameters die('payement status update bind_param() failed: ' . htmlspecialchars($stmt->error)); } if(!$stmt->execute()) { die('payement status update update execute() failed: ' . htmlspecialchars($stmt->error)); } source code:
<tr> <th class="thpayment">paid</th> <th class="thpayment">partially paid</th> <th class="thpayment">owes</th> </tr> <tr> <td class="tdpayment" id="paid" name="paid"> <div> <br /> <b>notice</b>: undefined variable: paid_name in <b>/home4/1/public_html/fdsf.com/usercreator.php</b> on line <b>116</b><br /> no 1 has paid </div> </td> <td class="tdpayment" id="partially_paid" name="partially_paid"> <div> <br /> <b>notice</b>: undefined variable: partially_paid__name in <b>/home4/1/public_html/tre.com/usercreator.php</b> on line <b>127</b><br /> no 1 has made partial payment </div> </td> <td class="tdpayment" id="owes" name="owes"> <div> hgfd <tr>
Comments
Post a Comment