PHP - insertar en PHP + MySQL + AJAX POO

 
Vista:
Imágen de perfil de Antonio
Val: 61
Ha aumentado 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

insertar en PHP + MySQL + AJAX POO

Publicado por Antonio (42 intervenciones) el 14/06/2020 22:48:12
Soy nuevo en esta parte de desarrollo en PHP y necesito hacer una inserción en MYSQL JS y PHP utilizados

pero no se que no funciona

tengo el indes con el formulario pero al momento de dar click en el boton no me hace la insercio, real mente no hace nada

este es mi codigo

formulario

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
include_once('class/productos.php');
$p = new Producto('','',0,'');
$p->Obtener();
$c = 3;
?>
<body>
    <h1 align="center">AGREGAR ITEM</h1>
	<table width="70%" border="1px" align="center">
<form>
<center>
 <br>
  <th><label>ID:<input type="text" id="id" name="id" value="<?php echo $p->id;?>"></label></th>
	<th><label>Nombre:<input type="text" id="nom" name="nom" value="<?php echo $p->nom;?>"><label></th>
	<th><label>Cantidad:<input type="text" id="cant" name="cant" value="<?php echo $p->cant;?>"><label></th>
	<th><label>Item:<input type="text" id="Item" name="Item" value="<?php echo $p->Item;?>"><label></th>
	<th><label><input type="button" name="op" id="op_<?php echo $c;?>" onclick="agregar(<?php echo $c;?>);" value="Agregar"><label></th>
 </br>
</center>
</form>
</table>
</body>

funcion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var x = $(document).ready(Ini);
 
function Ini(){
	$("#load").load("listados.php");
}
 
function Llamar(n){
	$.get("modificar.php",{id:n},function(data){
		$("#datos").html(data);
	});
}
 
function Agregar(n){
	$.get("agregar.php",{op:btn,id:idi,nom:nomb,cant:canti,Item:Item},function(data){
		$("#agregar").html(data);
	});
}
 
function Agregar(n){
	var btn = $("#op_"+n).val();
	var idi = $("#id").val();
	var nomb = $("#nom").val();
	var canti = $("#cant").val();
	var Item = $("#Item").val();
	$("#agregar").html('<img src="loading.gif">');
	$("#agregar").fadeTo("slow",0.1);
	$.get("operaciones.php",{op:btn,id:idi,nom:nomb,cant:canti,Item:Item});
}

index

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="function.js"></script>
</head>
<body>
<div id="encabezado">
<!--casa moa-->
</div>
<!--Div con el contenido-->
<div id="wrapper">
<center>
<h1>CASA MOA</h1></center>
<p>Aquí va algún texto y más abajo irían imágenes</p>
</div>
<div style='height: 220px; width: 220px; border: 3px'>
 
<!--Menú-->
<ul>
<li>Inicio</li>
<li>Clientes</li>
<li>Inventario</li>
<li>Nuevo Item</li>
<li>Vendedores</li>
<li>Venta</li>
<li>CuentasXPagar</li>
</ul>
</div>
<div style='height: 220px; width: 1500px; border: 3px'>
<div id="agregar"></div>
 
</div>
</body>
</html>


selecciona la operacion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
include_once('class/productos.php');
$p = new Producto($_REQUEST['id'],$_REQUEST['nom'],$_REQUEST['cant'],$_REQUEST['Item']);
 
$op = $_REQUEST['op'];
 
switch($op){
	case 'Modificar':
	$p->Modificar();
	break;
 
	case 'Eliminar':
	$p->Eliminar();
	break;
 
	case 'Agregar':
	$p->Agregar();
	break;
 
}
sleep(1);
?>

conexion con la BD

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
include_once('conexion.php');
 
class Producto{
 
	var $id;
	var $nom;
	var $cant;
	var $Item;
 
	function Producto($id=0,$nom='',$cant=0,$Item=''){
		$this->id=$id;
		$this->nom=$nom;
		$this->cant=$cant;
		$this->Item=$Item;
	}
  	function Agregar(){
    $con = new ConexionBD();
    $sql = "INSERT INTO productos (id, nom, cant, Item) VALUES ('".$this->id."', '".$this->nom."', '".$this->cant."', '".$this->Item."')";
 
		return $con->ejecutarsentencia($sql);
    }
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

insertar en PHP + MySQL + AJAX POO

Publicado por joel (1269 intervenciones) el 15/06/2020 08:17:04
Hola Antonio, así es muy dificil de ver donde puede estar el problema...

Has revisado la consola del navegador, haber que error te muestra?
Tienes el código publicado en Internet para poder probarlo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar