my code

Gonzalo Benoffi

Insert array via JSON - POST
by Gonzalo Benoffi

Snippet options

Download: Download snippet as insert-array-via-json-post.php.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

$json = new Services_JSON;
$db = new MySQL(); 	
mysql_query ("SET NAMES 'utf8'");   

$id_punto = $_POST['id_punto'];
$tipo_valoracion = $_POST['tipo_valoracion'];
$idUsuario = $_POST['idUsuario'];

$data = json_decode($_POST["arr"]);

$sql="INSERT INTO valoraciones (id_punto,id_usuario,tipo_valoracion) VALUES ('$id_punto','$idUsuario','$tipo_valoracion')";
$consulta = $db->consulta($sql); 
$idValoracion = mysql_insert_id();

echo $_POST["arr"];
echo '<br></br>';
// will echo the json_decode'd object

echo "tipo ".$tipo_valoracion;
echo '<br></br>';

if ($tipo_valoracion == "0")

foreach($data as $cityObject)
	echo "cityObject ".$cityObject->valor;
	echo '<br></br>';
	if ($cityObject->valor == 1)
		$sql="INSERT INTO denuncias (id_dato_incorrecto,id_valoracion,inputUsuario) VALUES ('$cityObject->id','$idValoracion','$cityObject->input')";
		$consulta = $db->consulta($sql); 

echo "1 record added";


Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.