Hello, they give me an error in the following line so that it is not doing it correctly:
$registro2 = $registro->fetchAll();
Full php code:
<?php
include('conexion.php');
$id = $_POST['id-prod'];
$proceso = $_POST['pro'];
$nombre = $_POST['nombre'];
$tipo = $_POST['tipo'];
$precio_uni = $_POST['precio-uni'];
$precio_dis = $_POST['precio-dis'];
$fecha = date('Y-m-d');
//VERIFICAMOS EL PROCESO
$query='';
require_once 'conexion.php';
$database_connection = database_connect();
switch($proceso){
case 'Registro':
$database_connection->query("INSERT INTO productos (nomb_prod, tipo_prod, precio_unit, precio_dist, fecha_reg)VALUES('$nombre','$tipo','$precio_uni','$precio_dis', '$fecha')");
break;
case 'Edicion':
$database_connection->query("UPDATE productos SET nomb_prod = '$nombre', tipo_prod = '$tipo', precio_unit = '$precio_uni', precio_dist = '$precio_dis' WHERE id_prod = '$id'");
break;
}
//ACTUALIZAMOS LOS REGISTROS Y LOS OBTENEMOS
$registro = $database_connection->query("SELECT * FROM productos ORDER BY id_prod ASC");
//CREAMOS NUESTRA VISTA Y LA DEVOLVEMOS AL AJAX
echo '<table class="table table-striped table-condensed table-hover">
<tr>
<th width="300">Nombre</th>
<th width="200">Tipo</th>
<th width="150">Precio Unitario</th>
<th width="150">Precio Distribuidor</th>
<th width="50">Opciones</th>
</tr>';
$registro2 = $registro->fetchAll();
foreach ($registro2 as $registro){
echo '<tr>
<td>'.$registro2['nomb_prod'].'</td>
<td>'.$registro2['tipo_prod'].'</td>
<td>S/. '.$registro2['precio_unit'].'</td>
<td>S/. '.$registro2['precio_dist'].'</td>
<td><a href="javascript:editarProducto('.$registro2['id_prod'].');" class="glyphicon glyphicon-edit"></a> <a href="javascript:eliminarProducto('.$registro2['id_prod'].');" class="glyphicon glyphicon-remove-circle"></a></td>
</tr>';
}
echo '</table>';
?>
The rest works well for me. It is a jquery registry with php and page. Basically what happens to me when I show with the foreach I get the following error, if I show a field nothing happens but if I show several it gives me this:
Notice: Undefined index: name_prod in C: \ wamp \ www \ www \ registration \ php \ add_product.php on line 42