All pastes #919093 Raw Edit

Miscellany

public text v1 · immutable
#919093 ·published 2008-02-26 16:20 UTC
rendered paste body
<?php
	//session_start();
	require 'json.php';
	function response2($array){
		header('Content-Type: text/plain; charset=utf8');
		echo json::encode($array);
		exit(0);
	}
	include("includes/functions.php");
	$categoria = sanitize($_POST["categoria"]);
	include("includes/conexion.php");
	$mypost = $categoria;
	$mytable = "categorias";
	$myrow = "categoria";
	$texto = "";
		if(validates_uniqueness_of($myrow,$mypost,$mytable)){
			$texto = "El nombre ".$categoria." ya existe en la base de datos";
		}
		else{
			$query = "insert into categorias (categoria) values ('$categoria')";
			$ejecutar = mysql_query($query);
				if($ejecutar){
					$response = array(
					'successMessage' => 'Insertando...',
					'redirectTo' => 'admin_categories.php'
					);
				}
				else{
				$texto = "El nombre ".$categoria." ya existe en la base de datos";
					$response = array(
					'errorMessage' => '<img src="images/loader.gif">Insertando...',
					'updateObject' => array( 
					'objectId' => 'mensaje',
					'data' => $texto
						)
					);
				}
			}
	response2($response);
?>