joaonunofz Posted March 11, 2014 at 08:00 PM Report #548274 Posted March 11, 2014 at 08:00 PM 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 } ?>
Devexz Posted March 11, 2014 at 09:25 PM Report #548280 Posted March 11, 2014 at 09:25 PM (edited) Esse erro dá em que linha de código? O erro está claro, não deves ter a key id definida no array que estás tentar aceder. Depois tens aqui um erro: $alterar = "UPDATE encomendas SET estado='".$_POST['CBXestado']."' WHERE id='".$_POST['$id']."' "; Na query decide-te se queres meter $_POST['id'] ou $id, porque aquilo que tens está errado. Edited March 11, 2014 at 09:26 PM by Devexz Contador de calorias: caloriaspordia.com
joaonunofz Posted March 12, 2014 at 11:29 PM Author Report #548453 Posted March 12, 2014 at 11:29 PM O erro está claro, não deves ter a key id definida no array que estás tentar aceder........ já agora podia ser mais especifico...ja vi q na instrução sql....está erro...mas q outro erro me esta a dizer??
I-NOZex Posted March 13, 2014 at 12:33 AM Report #548461 Posted March 13, 2014 at 12:33 AM $_POST é um array tu acedes aos indices/keys do array desta forma: $_POST['id'] até ai tudo bem, o que o erro diz, é que o indice/chave id não existe, ou seja, estás a aceder a uma posição inexistente da variavel resumindo, o teu formulario não está a enviar nenhum id B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
bioshock Posted March 13, 2014 at 10:07 AM Report #548475 Posted March 13, 2014 at 10:07 AM var_dump($_POST);
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now