What I want to do is that in a form have a select with the products and next to the select an input type = button where you add it to a table the data and that you can continue selecting more products to add it in the same table.
This is the form:
Another drawback I have are the add and cancel buttons as I could leave them after the table?
I have a code but I get an error every time I select the article of the select. This is the error:
I imagine that the error is due to several queries.
These are the files I have:
clientes.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Abonos</title>
<?php include 'inc/head_comun.php'; ?>
</head>
<body>
<?php include 'inc/menu.php'; ?>
<div class="container" >
<br>
<div class="panel panel-success">
<div class="panel-heading" align="center"><h3>CLIENTES</h3>
</div>
<div class="panel-body">
<div class="row" align="center">
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#nuevo"><span class="glyphicon glyphicon-user"></span>
Nuevo Cliente
</button>
</div>
<br>
<div class="table-responsive">
<table id="grid" class="table table-hover table-condensed nowrap dt-responsive" cellpadding="0">
<thead>
<tr class="active">
<th>Cedula</th>
<th >Nombre</th>
<th>Apellido</th>
<th>Direccion</th>
<th>Telefono</th>
<th>Celular</th>
<th>Correo</th>
<th>Prestamos</th>
<th>Opciones</th>
</tr>
</thead>
<?php
foreach ($matrizClientes as $clientes){
?>
<tr>
<td><?php echo $clientes["cedula"] ?></td>
<td><?php echo $clientes["nombre"] ?></td>
<td><?php echo $clientes["apellido"]?></td>
<td><?php echo $clientes["direccion"] ?></td>
<td><?php echo $clientes["telefono"] ?></td>
<td><?php echo $clientes["celular"] ?></td>
<td><?php echo $clientes["correo"] ?></td>
<td><a href="vista/frm_nueva_cuenta.php?id=<?php echo $clientes["id_cliente"] ?>"><input type="button" value="Asignar Cuenta" class="btn btn-info"></a></td>
<td align="center"><a href="vista/frm_editar_cliente.php?id_cliente=<?php echo $clientes["id_cliente"]?>"><span class="glyphicon glyphicon-check" title="Editar"></span></a>
<a onclick="return confirmDel();" href="modelo/eliminar_cliente.php?id_cliente=<?php echo $clientes["id_cliente"]?>"><span class="glyphicon glyphicon-remove" title="Eliminar"></span></a>
<?php
}
?>
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
frm_nueva_cuenta.php
<html>
<body>
<div class="container " >
<br>
<div class="panel panel-success">
<div class="panel-heading" align="center"><h3>Nueva Cuenta</h3>
</div>
<div class="panel-body">
<br>
<form class="form-horizontal" autocomplete="off" method="POST" action="insertar_cuenta.php" name="frm_articulo" style="margin:0 auto">
<div class="form-group" >
<?php
require_once "../modelo/Conectar.php";
$con=Conectar::conexion();
$id=$_GET['id'];
$prestamo=$con->query("SELECT det.total, det.cantidad, det.saldo, ar.art_nombre, ar.art_categoria, ar.art_color, cu.cue_forma_pago, cu.cue_vendedor, cu.fecha, c.cedula, c.nombre, c.apellido from detalle_cuenta det, articulo ar, cliente c, cuenta cu
where det.articulo=ar.id_articulo
and det.cuenta_id=cu.id_cuenta
and cu.cue_cliente='$id'")->fetchALL(PDO::FETCH_OBJ);
$cliente=$con->query("SELECT * FROM cliente WHERE id_cliente='$id'")->fetchALL(PDO::FETCH_OBJ);
$cliente=$cliente[0];
?>
<label class="control-label col-lg-4">Cliente</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="cliente" value="<?php echo $cliente->nombre.' ' .$cliente->apellido;?>" disabled>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Vendedor</label>
<div class="col-lg-4">
<input type="text" class="form-control" name="vendedor" onkeypress="return letras(event)">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Fecha</label>
<div class="col-sm-7">
<input type="date" style="width: 204px;" name="fecha" required value="<?php echo date("Y-m-d");?>"/>
</input>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Modo de pago</label>
<div class="col-sm-2">
<select name="formapago" id="formapago" style="width: 204px;">
<?php
if ($formapago->$prestamos=="Semanal")
{
?>
<option value="Semanal" selected="selected">Semanal</option>
<option value="Quincenal">Quincenal</option>
<option value="Mensual">Mensual</option>
<?php
}
if ($formapago->$prestamos=="Quincenal")
{
?>
<option value="Quincenal" selected="selected">Quincenal</option>
<option value="Semanal">Semanal</option>
<option value="Mensual">Mensual</option>
<?php
}
else{
?>
<option value="Semanal" >Semanal</option>
<option value="Quincenal" >Quincenal</option>
<option value="Mensual" selected="selected">Mensual</option>
<?php
}
?>
</select>
</div>
</div>
<?php
if(isset($_GET['opcion'])){
$sth1 = $con->prepare('select * from articulo where id_articulo = :id');
$sth1->bindParam(':id', $_GET['opcion']);
$sth1->execute();
$result1 = $sth1->fetchAll();
}
$sth = $con->prepare('SELECT * FROM articulo');
$sth->execute();
$result = $sth->fetchAll();
?>
<hr>
<h3 align="center">Agregando articulos</h3>
<div class="form-group">
<label class="col-lg-4 control-label">Articulo</label>
<div class="col-sm-2">
<select name="idArticulo" id="idArticulo" onchange="return buscar();" style="width: 204px;">
<?php
if($result1){?>
<option value="<?php echo $result1[0]['id_articulo'];?>">
<?php echo $result1[0]['art_nombre'];?>
</option>
<?php
}?>
<option value=""></option>
<?php
foreach ($result as $key => $value) {?>
<option value="<?php echo $value['id_articulo'];?>"><?php echo $value['art_nombre'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Cantidad</label>
<div class="col-xs-1">
<input type="text" class="form-control" name="interes" onkeypress="return numeros(event)">
</div>
<input type="button" class="btn btn-info" value="Agregar">
</div>
<div class="table-responsive">
<table id="grid" class="table table-hover table-condensed table-bordered nowrap dt-responsive" cellpadding="0">
<thead>
<tr class="active">
<th>Nombre</th>
<th>Categoria</th>
<th>Precio $ </th>
<th>Color</th>
</tr>
</thead>
<tr>
<td><?php if(isset($result1)){
echo $result1[0]['art_nombre'];
}else{
echo "";
}
?>
</td>
<td> <?php if(isset($result1)){
echo $result1[0]['art_categoria'];
}else{
echo "";
} ?>
</td>
<td> <?php if(isset($result1)){
echo $result1[0]['art_precio'];
}else{
echo "";
} ?>
</td>
<td> <?php if(isset($result1)){
echo $result1[0]['art_color'];
}else{
echo "";
} ?>
</td>
</tr>
<br><br>
<div class="row col-md-offset-3">
<button type="submit" name="actualizar" class="btn btn-success col-xs-12 col-md-2 col-md-offset-1">Agregar</button>
<button type="button" onclick="location='../clientes.php'" class="btn btn-danger col-xs-12 col-md-2 col-md-offset-1">Cancelar</button>
<input name="id" type="hidden" value="<?php echo $id; ?>"/>
</form>
</div>
</div>
</div>
</div>
<script>
function buscar(){
var opcion = document.getElementById('idArticulo').value;
window.location.href = 'http://localhost/credipaisa/vista/frm_nueva_cuenta.php?opcion='+opcion;
}
</script>
The file insertar_cuenta.php
I have not done since I could not make the form to add the articles to the account.