11-03-2014, 21:06
queria fazer um update na minha base de dados mysql...mas dá este erro:
Notice: Undefined index: id
meu codigo :
<?php
if(isset($_REQUEST['alterar'])){
require 'LIGACAO_bd.php';
$id = $_POST['id'];
$alterar = "UPDATE encomendas SET estado='".$_POST['CBXestado']."' WHERE id='".$_POST['$id']."' ";
$estado = mysql_query($alterar);
// Turn off all error reporting
error_reporting(0);
echo"<script>
alert('ESTADO DA ENCOMENDA ALTERADO');
location.href='ver_encomendas.php';
</script>";
}
else{
?>
<table width="1000" border="0" cellspacing="0" align="center" class="tabAZUL3">
<tr>
<td width="16" align="center" class="texto">ID</td>
<td width="105" align="center" class="texto">USUARIO</td>
<td width="201" align="center" class="texto">PRODUTO</td>
<td width="46" align="center" class="texto" title="QUANTIDADE">QTD</td>
<td width="76" align="center" class="texto">DOSE</td>
<td width="93" align="center" class="texto">DIA ENTREGA</td>
<td width="113" align="center" class="texto">HORA ENTREGA</td>
<td width="104" align="center" class="texto">DATA ENCOMENDA</td>
<td width="64" align="center" class="texto">ESTADO|</td>
<td width="86" align="left" class="texto">ATUALIZAR</td>
<td width="74"><input type="submit" disabled="disabled" value="ALTERAR" /></td>
</tr>
</table>
<?php
require 'LIGACAO_bd.php';
$escolher ="SELECT * FROM encomendas";
$consulta = mysql_query($escolher);
while($mostrar = mysql_fetch_array($consulta)){
$id = $mostrar['id'];
$nome =$mostrar['nome'];
$produto = $mostrar['produto'];
$quantidade = $mostrar['quantidade'];
$dose =$mostrar['dose'];
$dia_entrega =$mostrar['dia_entrega'];
$hora_entrega = $mostrar['hora_entrega'];
$data_encomenda = $mostrar['data_encomenda'];
$estado =$mostrar['estado'];
echo "<table width=\"1000\" border=\"0\" cellspacing=\"0\" align=\"center\" class=\"corTABELA\">
<tr>
<td width=\"24\" align=\"center\" class=\"texto\">$id</td>
<td width=\"80\" align=\"center\" class=\"texto\">$nome</td>
<td width=\"240\" align=\"center\" class=\"texto\">$produto</td>
<td width=\"30\" align=\"center\" class=\"texto\">$quantidade</td>
<td width=\"90\" align=\"center\" class=\"texto\">$dose</td>
<td width=\"92\" align=\"center\" class=\"texto\">$dia_entrega</td>
<td width=\"106\" align=\"center\" class=\"texto\">$hora_entrega</td>
<td width=\"130\" align=\"center\" class=\"texto\">$data_encomenda</td>
<td align=\"center\" class=\"texto\">$estado</td>
<td><form name=\"CBXaltera\" action=\"ver_encomendas.php\" method=\"post\">
<select name=\"CBXestado\">
<option value=\"pendente\">pendente</option>
<option value=\"feita\">feita</option>
<option value=\"esgotado\">esgotado</option>
</td>
<td><input type=\"submit\" name=\"alterar\" value=\"ALTERAR\" TITLE=\"ATUALIZA O ESTADO DESTA ENCOMENDA\" <input type=\"hidden\" name=\"id\" value=\"<?php echo $id; ?>\" >
</form></td>
</tr>
</table>";
}
// liberta da memoria a variavel $consulta
mysql_free_result($consulta);
?>
<?php } ?>
Notice: Undefined index: id
meu codigo :
<?php
if(isset($_REQUEST['alterar'])){
require 'LIGACAO_bd.php';
$id = $_POST['id'];
$alterar = "UPDATE encomendas SET estado='".$_POST['CBXestado']."' WHERE id='".$_POST['$id']."' ";
$estado = mysql_query($alterar);
// Turn off all error reporting
error_reporting(0);
echo"<script>
alert('ESTADO DA ENCOMENDA ALTERADO');
location.href='ver_encomendas.php';
</script>";
}
else{
?>
<table width="1000" border="0" cellspacing="0" align="center" class="tabAZUL3">
<tr>
<td width="16" align="center" class="texto">ID</td>
<td width="105" align="center" class="texto">USUARIO</td>
<td width="201" align="center" class="texto">PRODUTO</td>
<td width="46" align="center" class="texto" title="QUANTIDADE">QTD</td>
<td width="76" align="center" class="texto">DOSE</td>
<td width="93" align="center" class="texto">DIA ENTREGA</td>
<td width="113" align="center" class="texto">HORA ENTREGA</td>
<td width="104" align="center" class="texto">DATA ENCOMENDA</td>
<td width="64" align="center" class="texto">ESTADO|</td>
<td width="86" align="left" class="texto">ATUALIZAR</td>
<td width="74"><input type="submit" disabled="disabled" value="ALTERAR" /></td>
</tr>
</table>
<?php
require 'LIGACAO_bd.php';
$escolher ="SELECT * FROM encomendas";
$consulta = mysql_query($escolher);
while($mostrar = mysql_fetch_array($consulta)){
$id = $mostrar['id'];
$nome =$mostrar['nome'];
$produto = $mostrar['produto'];
$quantidade = $mostrar['quantidade'];
$dose =$mostrar['dose'];
$dia_entrega =$mostrar['dia_entrega'];
$hora_entrega = $mostrar['hora_entrega'];
$data_encomenda = $mostrar['data_encomenda'];
$estado =$mostrar['estado'];
echo "<table width=\"1000\" border=\"0\" cellspacing=\"0\" align=\"center\" class=\"corTABELA\">
<tr>
<td width=\"24\" align=\"center\" class=\"texto\">$id</td>
<td width=\"80\" align=\"center\" class=\"texto\">$nome</td>
<td width=\"240\" align=\"center\" class=\"texto\">$produto</td>
<td width=\"30\" align=\"center\" class=\"texto\">$quantidade</td>
<td width=\"90\" align=\"center\" class=\"texto\">$dose</td>
<td width=\"92\" align=\"center\" class=\"texto\">$dia_entrega</td>
<td width=\"106\" align=\"center\" class=\"texto\">$hora_entrega</td>
<td width=\"130\" align=\"center\" class=\"texto\">$data_encomenda</td>
<td align=\"center\" class=\"texto\">$estado</td>
<td><form name=\"CBXaltera\" action=\"ver_encomendas.php\" method=\"post\">
<select name=\"CBXestado\">
<option value=\"pendente\">pendente</option>
<option value=\"feita\">feita</option>
<option value=\"esgotado\">esgotado</option>
</td>
<td><input type=\"submit\" name=\"alterar\" value=\"ALTERAR\" TITLE=\"ATUALIZA O ESTADO DESTA ENCOMENDA\" <input type=\"hidden\" name=\"id\" value=\"<?php echo $id; ?>\" >
</form></td>
</tr>
</table>";
}
// liberta da memoria a variavel $consulta
mysql_free_result($consulta);
?>
<?php } ?>