PHP,Js sending values from the datatable to database ( Need help asap )

PHP,Js sending values from the datatable to database ( Need help asap )

KavvsonKavvson Posts: 1Questions: 0Answers: 0
edited November 2013 in General
Hello guys I have faced a big problem for my small app using datatable.
It sends to database only 10 rows ( im also concerned how it should be applied to the database ( does the post method works if I will have 200 numbers ( each 24 digitals ) ? Or should I use other method. Please help me out.

Code of adding. You type a List number then you might add a number ( each new added, will add to the table dynamicaly ) then we send it to the databse.

[code] <?PHP

if (!defined("_VALID_PHP"))
die('Direct access to this location is not allowed.');
$db_handler = new PDO('mysql:host=localhost;dbname=proj2', 'root', '');
?>


@import "datatable/media/css/demo_table.css";




$(document).ready(function(){
var oTable;
oTable = $('#subitemsTbl').dataTable();

var rowNum = 0;
function addDetails() {
rowNum ++;
//var row = '';
var row = ''+rowNum+'';
var displll = '  '+rowNum+'  ';
$('#body').append(row);

// add new row to datatable

$('#subitemsTbl').dataTable().fnAddData( [
rowNum,
'',
'' ] );

document.getElementById("counter").innerHTML = "INP: " + rowNum ;
return false;
};

$(document).on('click', '.removeRow', function() {

//$('#rowNum'+this.id).remove();
var target_row = $(this).closest("tr").get(0); // this line did the trick
var aPos = oTable.fnGetPosition(target_row);
oTable.fnDeleteRow(aPos);
rowNum--;
document.getElementById("counter").innerHTML = "INP: " + rowNum ;
});

$("#subInput").keydown(function(event){
if ( event.keyCode == 46 || event.keyCode == 8 ) {
// let it happen, don't do anything
}else if (event.keyCode < 48 || event.keyCode > 57 ) {
event.preventDefault();
}
var remainingChars = $(this).val().length;
if (remainingChars == 24) {
addDetails();
$(this).val(''); // does empty the text input

}
});

$("#mainItem").keydown(function(event){
if ( event.keyCode == 46 || event.keyCode == 8 ) {
// let it happen, don't do anything
}else if (event.keyCode < 48 || event.keyCode > 57 ) {
event.preventDefault();
}
var remainingChars = $(this).val().length;
if (remainingChars == 24) {
$(this).attr('readonly','readonly');
}
});

});





Generate List


Wystawcze
On:   

<?PHP
$sql = 'SELECT id, name, surname FROM customers ORDER BY name';
foreach ($db_handler->query($sql) as $row) {
echo "".$row['name'] ." ".$row['surname']. "";
}
?>

ID: <?PHP echo $user->getID(); ?>


Type
Prority:   

Normal
High


List type :  

Normal
Other


Letters:



Counter






List Numbers:


Numbers :



<!-- OLD TABLE START -->



<!-- DATA TABLE -->




Lp
Numer
Akcje














<?php
if(isset($_POST['submit'])){


if($_POST['mainItem'] == NULL){
echo $core->msgError("Alert!List number field empty.",false);
}else{
//Handle main item already exists error
try {
$stmt = $db_handler->prepare('SELECT * FROM listy WHERE number=?');
$stmt->bindValue(1, $_POST['mainItem'], PDO::PARAM_STR);
$stmt->execute();
$row_count = $stmt->rowCount();
if($row_count > 0){ header('location: ?error=1'); exit();}
} catch(PDOException $ex) {
die($ex->getMessage());
}

try {
$stmt = $db_handler->prepare('INSERT INTO listy (number,letters,forwho,bywho,prority,type) VALUES(?,?,?,?,?,?)');
$stmt->bindValue(1, $_POST['mainItem'], PDO::PARAM_STR);
$stmt->bindValue(2, $_POST['letters'], PDO::PARAM_INT);
$stmt->bindValue(3, $_POST['forwho'], PDO::PARAM_INT);
$stmt->bindValue(4, $user->getID(), PDO::PARAM_INT);
$stmt->bindValue(5, $_POST['priority'], PDO::PARAM_INT);
$stmt->bindValue(6, $_POST['type'], PDO::PARAM_INT);
$stmt->execute();
} catch(PDOException $ex) {
die($ex->getMessage());
}

//Insert loop
$mainRowId = 0;
$mainRowId = $db_handler->lastInsertId();
$sub_items = array_unique($_POST['subItem']);
//print_r($_POST);
//print_r($sub_items);
foreach($sub_items as $this_sub){
//echo $this_sub;
try {
$stmt = $db_handler->prepare('INSERT INTO numbers (`list_id`,`number`,`return`) VALUES(?,?,?)');
$stmt->bindValue(1, $mainRowId, PDO::PARAM_INT);
$stmt->bindValue(2, $this_sub, PDO::PARAM_STR);
$stmt->bindValue(3, 0, PDO::PARAM_INT);
$stmt->execute();

$subRowId = 0;
$subRowId = $db_handler->lastInsertId();
$stmt = $db_handler->prepare('INSERT INTO list_has_number (`list_id`,`number_id`) VALUES(?,?)');
$stmt->bindValue(1, $mainRowId, PDO::PARAM_INT);
$stmt->bindValue(2, $subRowId, PDO::PARAM_INT);
$stmt->execute();

} catch(PDOException $ex) {
die($ex->getMessage());
}
}


}
unset($_POST['submit']);
unset($sub_items);
unset($_POST['mainItem']);
}
[/code]
This discussion has been closed.