0

I have problem save to dabatase with ajax. if only ajax alert , Working but , if save to database , not saved. in the code , i try echo , but no show result

I have problem save to dabatase with ajax. if only ajax alert , Working but , if save to database , not saved. in the code , i try echo , but no show result

<script>
$(document).ready(function() {

  $("#myTable").on('click', '.btnSelect', function() {

    var currentRow=$(this).closest("tr"); 

    var col1 = currentRow.find("td:eq(0)").text();

    var col2 = currentRow.find("td:eq(1)").text();

    var col3 = currentRow.find("td:eq(2)").text();

    var col4 = currentRow.find("td:eq(3)").text();

    var col5 = currentRow.find(":selected").text();

    var col6 = currentRow.find("input[name='qtyorder[]']").val();

//    var data = col1 + "\n" + col2 + "\n" + col3 + "\n" + col4 + "\n" + col5 + "\n" + col6;

//    alert(data);

                         $.ajax({
                        type: "POST",
                        url: "b_save_data_total_resin_based_po_customer.php",
                        data: "bulanpo=" + col1+ "&supplier=" + col2"&qtypo=" + col3"&resin=" + col4"&bulanorder=" + col5"&qtyorder=" + col6,
                        success: function(data) {
                           alert("sucess");
                        }
                    });


  });

});
//*
</script>

b_save_data_total_resin_based_po_customer.php

<?php
include "session.php";
include "header.php";
include "navigasi.php";
$username = $login_session;

$bulanorder = $_GET['bulanorder'];
$qtyorder = $_GET['qtyorder'];
$today = date("Y-m-d");
$bulanpo = $_GET['bulanpo'];
$qtypo = $_GET['qtypo'];
$supplier = $_GET['supplier'];
$resin = $_GET['resin'];


       $sql="
       INSERT INTO order_resin_to_supplier (transaction_id,date_transaction,bulanpo,supplier,qtypo,resin,bulanorder,qtyorder,username,date_input) 
       VALUES ('test','$today','$bulanpo','$supplier','$qtypo','$resin','$bulanorder','$qtyorder','$username','$today')";
     //  $sql = $conn->query($sql);

    echo $sql;   
//$conn->close(); 
?>

need help thanks

  • What does `alert(data)` output? Ensure that all the fields are being passed as you are making use of `$_GET` which throws errors when a index is not set. – Script47 Sep 06 '17 at 14:42
  • Did you check php receive data values correctly? – SilverSurfer Sep 06 '17 at 14:42
  • 4
    `// $sql = $conn->query($sql);` no wonder it doesn't inserts, it's never executed. – Qirel Sep 06 '17 at 14:43
  • You're not executing the query. You have commented out the line which executes the insert – kinggs Sep 06 '17 at 14:43
  • 5
    You're sending a POST request and expecting the parameters via GET. – taavs Sep 06 '17 at 14:43
  • 2
    You're already using an API that supports **prepared statements** with bounded variable input, you should utilize parameterized queries with placeholders (prepared statements) to protect your database against [SQL-injection](http://stackoverflow.com/q/60174/)! Get started with [`mysqli::prepare()`](http://php.net/mysqli.prepare) or [`PDO::prepare()`](http://php.net/pdo.prepare) – Qirel Sep 06 '17 at 14:43
  • yes , true , i check echo...but no result. – andry gusnardry Sep 06 '17 at 14:44
  • Rather than passing the `data` variables as a string, make use of an object. – Script47 Sep 06 '17 at 14:44
  • 1
    @Script47 Hehe, indeed - there are two typos (commented the query out and POST/GET) though, but still :-) – Qirel Sep 06 '17 at 14:44
  • how to correct , please. – andry gusnardry Sep 06 '17 at 16:48

0 Answers0