0
I have a Javascript form that sends a array, however I am not able to recover the columns and their values of the array to insert into a Mysql database with PHP.
Example of array
{"id_deb":"","codbar":"123","id_cat":"20","id_emp":"89","date_at":"2019-
04-25","valor":"222.22","status":1}
PHP code
<?php
include ('../../../../../../server/lib/Connection.class.php');
//print_R($_POST);
$sql = "INSERT INTO `debitos` (codbar,categoria_id,empresa_id) VALUES('" . $_POST["codbar"] . "', '" . $_POST["id_cat"] . "','" . $_POST["id_emp"] . "')";
$result = @mysql_query($sql);
if ($result){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('msg'=>'Erro ao inserir dados.'));
}
?>
Hello @Aiolos, welcome to Sopt! Add your code
php
so that the staff can help, without it becomes difficult to assist in the solution.– 8biT
include ('../../.../../../server/lib/Connection.class.php'); //print_R($_POST); $sql = "INSERT INTO
debitos
(codbar,categoria_id,empresa_id) VALUES('" . $_POST["codbar"] . " ', '" . $_POST["id_cat"] . " ','" . $_POST["id_emp"] . " ')"; $result = @mysql_query($sql); if ($result){ echo json_encode(array('Success'=>true); } Else { echo json_encode(array('msg'=>'Error inserting data. '); }– user147379
Add the code to the question for easy reading
– Leonardo Barros
Missing javascript code sending array
– Leonardo Barros
Must-read: Why should we not use mysql type functions_*? And never use the
@
in function calls. If you do not know what is happening, it will only harm you; if you know what is happening you will avoid.– Woss
How does it get in php?
– adventistaam