Registration entry with Ajax to bd

0

Hello good morning to all I hope you can help me, the question is that I am doing a control panel using ajax, the client entered it into 4 different tables and in the 4 tables it enters double the record. Thank you in advance.

I leave the code

document.getElementById("btn-agregar-cliente").addEventListener("click",peticion_agregar_cliente)

function peticion_agregar_cliente()
{
	
	var cliente=document.getElementById("cliente-nuevo").value

	if(confirm("¿DESEAS INGRESAR AL CLIENTE: '"+cliente+"' A LA LISTA?"))
	{

		if (window.XMLHttpRequest) 
			    	
			    	{
			            // codigo para IE7+, Firefox, Chrome, Opera, Safari
			            peticion = new XMLHttpRequest()
			            
	        		} 
	        		else 
	        		{
	            		// codigo para IE6, IE5
	            		peticion = new ActiveXObject("Microsoft.XMLHTTP")
	            		
	        		}

	        	

	        	var url_agregar="operaciones-bd-panel/agregar-cliente.php?cliente="+cliente

        			peticion.onreadystatechange = function() 
	        		{
	            		if (this.readyState == 4 && this.status == 200) 
	            		{
	                		document.getElementById("indicador-actualizacion").innerHTML = this.responseText
	                		setTimeout(actualizar_lista_clientes,1000)
	                		
	            		}
	        		};

	        	peticion.open("GET",url_agregar,true)
	        	peticion.send()		
	


	}
	
		

	   

}
/*
Este es el codigo php al momento de invocar ajax

agregar-cliente.php

<?

try 
{	
	$tablas_actualizar=array("campos_articulos","campos_tiendas","posicion_articulos","posicion_tiendas");

	include("../conexion.php");

	for ($indice=0; $indice <count($tablas_actualizar); $indice++) 
	{ 
		$sql="INSERT INTO ".$tablas_actualizar[$indice]." (cliente) VALUES ('".$_GET['cliente']."')";
		$actualizar=$base->query($sql);
		$actualizar->execute();
	}

		echo "CLIENTE ".$_GET['cliente']." AGREGADO";
	

	
} catch (Exception $e)

{
	
		echo "ERROR AL INGRESAR CLIENTE :".$e->getline();
}


?>



*/
<html>
<div id="area-agregar-cliente" class="col-xl-4 col-lg-4 col-md-12 col-sm-12">
				
				<h4>Agregar cliente</h4>

				<input type="text" id="cliente-nuevo" placeholder="Ingrese cliente">
					
				<input id="btn-agregar-cliente" type="button" value="AGREGAR">

</div>
</html>
    
asked by RICHI150 20.06.2017 в 21:12
source

0 answers