Hello.
I'm new to php and sql.
I nee to insert data in multiple tables and rows. the problem, in the first table, I just nedd 1 row, and that's fine, in the scond i need to input data in the minimum of 1 row and max of 6 row's. in the second table, no data is inserted, can you help me?? Thanks in advance.
php code ( entrada.php)
<?php
//conecção ao servidor
$conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
$db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");
// VAriaveis
//ordem
$data = date("dmY");
$nordem = $_POST['nordem'];
$guian = $_POST['guian'];
$ncliente = $_POST['ncliente'];
$cliente = $_POST['cliente'];
$fornecedor = $_POST['fornecedor'];
// entrada linha1
$check = $_POST['check'][$i];
$lote = $_POST['lote'][$i];
$val = $_POST['val'][$i];
$designacao = $_POST['designacao'][$i];
$filtro = $_POST['filtro'][$i];
$familiamarca = $_POST['familiamarca'][$i];
$quantguia = $_POST['quantguia'][$i];
$quantconf = $_POST['quantconf'][$i];
$atado = $_POST['atado'][$i];
$posicao = $_POST['posicao'][$i];
$codprod = $_POST['codprod'][$i];
echo $sql="INSERT INTO ordem(data, nordem, fornecedor, guian, ncliente, cliente)
VALUES( '".$data."', '".$nordem."', '".$fornecedor."', '".$guian."', '".$ncliente."', '".$cliente."')";
echo "</br>";
mysql_query ($sql);
$exec=mysql_query($sql);
echo $sql = 'INSERT INTO \'entrada\' (\'nordem_n\', \'lote\', \'val\', \'designacao\', \'familiamarca\', \'quantguia\', \'quantconf\', \'atado\', \'posicao\', \'codprod\') VALUES';
for ($i=0; $i<count($_POST['lote']); $i++) {
$sql .= '(\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
if ($i<count($_POST['lote']) - 1) {
$sql .= ',';
}
}
?>
<?php
mysql_close();
?>
html code ( form.html)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ficha de entrada de material</title>
<meta name="alex" content="sermail" />
<link rel="stylesheet" type="text/css" href="styles/styles.css" />
<script type="text/javascript">
function printpage()
{
window.print()
}
</script>
<script>
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
</script>
<style type="text/css" media="print">
.printbutton {
visibility: hidden;
display: none;
}
.validado {
visibility: hidden;
display: none;
}
.background{ color: #0000;}
.page landscape {size: landscape;}
.page
{ bgcolor: #0000; }
.h1{color: #000;
font-family: Times New Roman, sans-serif;
font-size: 18px;
font-weight: bold;
text-align: left;}
.h2{color: #000;
font-weight: normal;
text-align: center;
font-family: Times New Roman, sans-serif;
font-size: 16px;}
</style>
</head>
<body bgcolor= #00814B>
<div class="body">
<div class="content">
<br><br><br><br><br>
<form action="entrada.php" method="post">
<table width="1000px"> <tr><td width="600px"><h1>
N.º Ordem: <input type="text" size="6" name="nordem" />
Fornecedor: <input type="text" size="10" name="fornecedor"/><br>
Guia n.º: <input type="text" size="6" name="guian"/>
N.º Cliente: <input type="text" size="8"name="ncliente" />
Cliente: <input type="text" size="15"name="cliente" /></h1></td><td width="250px"</td><td><img src="imas/sermaillogo.png"></td></tr>
<table border="1" id="produtos" width="900px" >
<tr ><td></td>
<td width="80px"><h2>Cód. <br/>Produto </h2></td>
<td width="80px"><h2>Cód. Cliente 1<br>Lote</h2></td>
<td width="80px"><h2>Cód. Cliente 2<br>validade</h2></td>
<td width="80px"><h2>Designação</h2></td>
<td width="80px"><h2>Filtro 1 <br> Unidade de negócio</h2></td>
<td width="80px"><h2>Familia/Marca</h2></td>
<td width="80px"><h2>Quant. Guia</h2></td>
<td width="80px"><h2>Quant. Conferida</h2></td>
<td width="80px"><h2>Atado</h2></td>
<td width="80px"><h2>Posição</h2></td>
</tr>
<tr><td><input type="hidden" name="check[]" value="0" /><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
<tr><td><input type="hidden" name="check[]" value="0" /><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
<tr><td><input type="hidden" name="check[]" value="0" /><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
<tr><td><input type="hidden" name="check[]" value="0" /><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
<tr><td><input type="hidden" name="check[]" value="0" /><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
<tr><td><input type="checkbox" name="check[]" value="1" /></td>
<td width="80px"><input type="text" size="8"name="codprod[]" /></td>
<td width="80px"><input type="text" size="8"name="lote[]" /></td>
<td width="80px"><input type="text" size="10"name="val[]" /></td>
<td width="80px"><input type="text" size="30"name="designacao[]" /></td>
<td width="80px"><input type="text" size="10"name="filtro[]" /></td>
<td width="80px"><input type="text" size="15"name="familiamarca[]"/></td>
<td width="80px"><input type="text" size="6"name="quantguia[]" /></td>
<td width="80px"><input type="text" size="6"name="quantconf[]" /></td>
<td width="80px"><input type="text" size="6"name="atado[]" /></td>
<td width="80px"><input type="text" size="6"name="posicao[]" /></td>
</tr>
</table>
<input type="submit"/ class="printbutton" value="Inserir entrada"><br/>
<input type="button"class= "validado" value="Imprimir" onclick="printpage()" />
<INPUT type="button" value="Fechar" onClick="window.close()">
</form>
</div>
</div>
</body>
</html>