jQuyer invoice doesn’t insert in WordPress custom table
-
First of all you can check https://prnt.sc/O7dfX2q-pHYB.I am trying to develop like this. But Multiple rows data doesn’t insert in the custom table only one row insert i used Ajax for data insert.I know there was simple issues.But I cant find out the issues. I used multiple insert script. Please help me to solve the issues.
Insert Code -1
for ($a = 0; $a < count($_POST['product']); $a++) { $table_name = $wpdb->prefix . 'estimate_details'; $data= array( 'itr_estimate_nbr' => sanitize_text_field($_POST['estmateno']), 'itr_pro_name' => sanitize_text_field($_POST['product'][$a]), 'itr_description' => sanitize_text_field($_POST['description'][$a]), 'itr_qtn' => sanitize_text_field($_POST['qty'][$a]), 'itr_rate' => sanitize_text_field($_POST['price'][$a]), 'itr_rate_total' => sanitize_text_field($_POST['total'][$a]) ); $format = array( '%d', '%s', '%s', '%d', '%d', '%f' ); $wpdb->insert($table_name,$data,$format); }
code insert-2
$table_name = $wpdb->prefix . 'estimate_details'; for ($a = 0; $a < count($_POST['product']); $a++) { $wpdb->insert( $table_name, array( 'itr_estimate_nbr' => $wpdb->prepare( '%d', $_POST['estmateno'] ), 'itr_pro_name' => $wpdb->prepare( '%s', $_POST['product'][$a] ), 'itr_description'=> $wpdb->prepare( '%s', $_POST['description'][$a] ), 'itr_qtn'=> $wpdb->prepare( '%d', $_POST['qty'][$a] ), 'itr_rate'=> $wpdb->prepare( '%d', $_POST['price'][$a] ), 'itr_rate_total'=> $wpdb->prepare( '%f', $_POST['total'][$a] ), ) ); }
Ajax script
jQuery(document).on('click', '#addInvoice', function () { var product = document.getElementById('product').value; var description = document.getElementById('description').value; var qty = document.getElementById('qty').value; var price = document.getElementById('price').value; var total = document.getElementById('total').value; jQuery.ajax({ url: ajax_url, type: "POST", cache: false, data: { 'action':'new_db_estimate_info', 'product' : product, 'description' : description, 'qty' : qty, 'price' : price, 'total' : total, }, success:function(data) { jQuery('body #message').html('Customer created successfully'); if(data=='Message sent successfully'){ jQuery('#message').text(data.message); jQuery("form").trigger("reset"); }else{ jQuery('#survey_error_message').text(data); jQuery("form").trigger("reset"); } }, error: function(errorThrown){ console.log(errorThrown); } }); });
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘jQuyer invoice doesn’t insert in WordPress custom table’ is closed to new replies.