Whiteangel Posted February 15, 2014 at 11:39 PM Report #545437 Posted February 15, 2014 at 11:39 PM Boas pessoal, Estou a criar um registo e que queria fazer o alterar, tenho uma pagina para escolher o registo (nome) alterar, depois manda me os campos para as textbox,até aqui faz muito bem... mas agora não sei como faça o UPDATE , para me alterar o registos ao clicar no botao alterar. Podem ajudar-me, orientar??? <form name="formularioPesquisa" method="POST" action="http://localhost/Gestao_Empresarial/AlterarClientes.php"> <blockquote> <label for="pesquisa"><font size="5">Nome:</font></label> <input class="textbox"type="text" name="Nome"> <input type="submit" value="Alterar" class="botao" name="Guardar" /> </br></blockquote> </form> <?php $nome=$_POST ['Nome']; if(!$nome) { echo "<script language='javascript' type='text/javascript' text-align:'center' > alert('Preencha o nome do cliente que deseja alterar...'); window.location.replace('http://localhost/Gestao_Empresarial/AlterarClientes.html'); </script>"; } $conexao=mysql_connect('localhost','root','1807'); if (!$conexao) {echo ' falha na ligação. </br>'; echo mysql_error(); exit;} else { mysql_select_db("empresa",$conexao); $resultado=mysql_query("select* from clientes where nome='".$nome."'"); echo ' <form name="formularioPesquisa11" method="POST" action="http://localhost/Gestao_Empresarial/AlterarClientes1.php">'; while($row= mysql_fetch_array($resultado)){ echo '<blockquote style="padding-left:5px">'; echo ' '; echo '<font color="#FFFFFF" size="3" face="Verdana" >Nome:</font><label style="padding-left:8px"><input type="text" name="nome" value='.$row['nome'].' class="textboxNome"><p></label>'; echo ' '; echo '<font color="#FFFFFF" size="3" face="Verdana" >Morada:</font><label style="padding-left:8px"><input type="text" name="morada" value='.$row['morada'].' class="textboxNome"<p><p style="padding-left:15px"></label> '; echo '<font color="#FFFFFF" size="3" face="Verdana" >Localidade:</font><label style="padding-left:8px"><input type="text" name="localidade" value='.$row['localidade'].' class="textboxNome" ><p></label>'; echo ' '; echo '<font color="#FFFFFF" size="3" face="Verdana" >E-mail:</font><label style="padding-left:8px"><input type="text" name="email"value='.$row['email'].' class="textboxNome"><p></label>'; echo ' '; echo '<font color="#FFFFFF" size="3" face="Verdana" >Telf/Telm:</font><label style="padding-left:8px"><input type="text" name="telefone" value='.$row['telefone'].' class="textboxTelefone"></label>'; echo ' '; echo '<font color="#FFFFFF" size="3" face="Verdana" >Nif:</font><label style="padding-left:8px"><input type="text" name="nif" value='.$row['nif'].' class="textboxTelefone"></label>'; echo ' <a href="http://localhost/Gestao_Empresarial/AlterarClientes1.php"" /><input type="button" class= "botao" value="Alterar" name="Guardar"/></a>'; echo '</blockquote>'; echo '</form>'; } } mysql_close($conexao); ?>
yoda Posted February 15, 2014 at 11:57 PM Report #545441 Posted February 15, 2014 at 11:57 PM Para que serve o alert? before you post, what have you tried? - http://filipematias.info sense, purpose, direction
I-NOZex Posted February 16, 2014 at 12:03 AM Report #545442 Posted February 16, 2014 at 12:03 AM http://www.w3schools.com/php/php_mysql_update.asp B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Whiteangel Posted February 16, 2014 at 12:06 AM Author Report #545443 Posted February 16, 2014 at 12:06 AM Para que serve o alert? O alert e da pagina anterior se nao digitao o nome do registo que quer alterar http://www.w3schools.com/php/php_mysql_update.asp Mas como faço o UPDATE uma vez que eu estou ja a mandar os dados para as texbox?
yoda Posted February 16, 2014 at 02:29 AM Report #545444 Posted February 16, 2014 at 02:29 AM (edited) Para validares o formulário : if (array_key_exists('Guardar', $_POST)) { $id = $_POST['id']; $nome = $_POST['nome']; $morada = $_POST['morada']; // ... etc // !! cuidado com a segurança aqui $sql = "UPDATE clientes SET nome = $nome, morada = $morada WHERE id = $id"; mysql_query($sql); } Edited February 16, 2014 at 02:31 AM by yoda before you post, what have you tried? - http://filipematias.info sense, purpose, direction
Whiteangel Posted February 16, 2014 at 11:38 AM Author Report #545453 Posted February 16, 2014 at 11:38 AM (edited) Para validares o formulário : if (array_key_exists('Guardar', $_POST)) { $id = $_POST['id']; $nome = $_POST['nome']; $morada = $_POST['morada']; // ... etc // !! cuidado com a segurança aqui $sql = "UPDATE clientes SET nome = $nome, morada = $morada WHERE id = $id"; mysql_query($sql); } Aqui o guardar é o quê? if (array_key_exists('Guardar', $_POST)) Edited February 16, 2014 at 11:39 AM by Whiteangel
I-NOZex Posted February 16, 2014 at 03:11 PM Report #545471 Posted February 16, 2014 at 03:11 PM Aqui o guardar é o quê? if (array_key_exists('Guardar', $_POST)) é para verificar que o parametro Guardar , que provavelmente deve ser o name do botão de submit, existe tens tambem a alternativa desta forma: if (isset($_POST['Guardar'])){ B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Whiteangel Posted February 16, 2014 at 03:57 PM Author Report #545478 Posted February 16, 2014 at 03:57 PM é para verificar que o parametro Guardar , que provavelmente deve ser o name do botão de submit, existe tens tambem a alternativa desta forma: if (isset($_POST['Guardar'])){ Não me está alterar , imprime sempre nao alterado mysql_select_db("empresa", $conexao); if (isset($_POST['Guardar'])){ $nome=$_POST['nome']; $telefone=$_POST['telefone']; $email=$_POST['email']; $morada=$_POST['morada']; $localidade=$_POST['localidade']; $nif=$_POST['nif']; $id=""; $sql = "UPDATE clientes SET nome = $nome, telefone = $telefone, email = $email, localidade = $localidade, morada = $morada, nif = $nif WHERE id = $id"; mysql_query($sql); echo 'Alterado<br>';} else { echo 'Não alterado<br>'; }
Devexz Posted February 16, 2014 at 04:12 PM Report #545480 Posted February 16, 2014 at 04:12 PM já experimentas-te ver se realmente recebes algum valor do form? faz aí um print_r($_POST), antes do if e mostra o ouput. Contador de calorias: caloriaspordia.com
Whiteangel Posted February 16, 2014 at 04:20 PM Author Report #545481 Posted February 16, 2014 at 04:20 PM (edited) já experimentas-te ver se realmente recebes algum valor do form? faz aí um print_r($_POST), antes do if e mostra o ouput. Já fiz resultado : array com os valores do registo que quero alterar mas diz mysql error Edited February 16, 2014 at 04:31 PM by Whiteangel
I-NOZex Posted February 17, 2014 at 11:36 AM Report #545537 Posted February 17, 2014 at 11:36 AM aseguir ao mysql_query, mete isto: die(mysql_error()); e diz o que aparece B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Whiteangel Posted February 17, 2014 at 09:03 PM Author Report #545598 Posted February 17, 2014 at 09:03 PM (edited) aseguir ao mysql_query, mete isto: die(mysql_error()); e diz o que aparece Aparece me isto You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.com, localidade = lisboa, morada = rua, nif = 852963566 WHERE id =' at line 1 Edited February 17, 2014 at 09:03 PM by Whiteangel
Devexz Posted February 17, 2014 at 09:23 PM Report #545605 Posted February 17, 2014 at 09:23 PM onde é que estão as aspas na tua query? 😕 Contador de calorias: caloriaspordia.com
HappyHippyHippo Posted February 17, 2014 at 09:34 PM Report #545608 Posted February 17, 2014 at 09:34 PM onde é que estão as aspas na tua query? 😕 não são aspas (") mas sim apostrofes (') ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Whiteangel Posted February 17, 2014 at 09:42 PM Author Report #545611 Posted February 17, 2014 at 09:42 PM não são aspas (") mas sim apostrofes (') ... Mas nem assim me dá $sql = "UPDATE clientes SET nome ='$nome_novo', telefone ='$telefone_novo', email ='$email_novo', localidade ='$localidade_novo', morada ='$morada_novo', nif ='$nif_novo' WHERE id ='$id'";
HappyHippyHippo Posted February 17, 2014 at 09:44 PM Report #545613 Posted February 17, 2014 at 09:44 PM porque é que esta questão existe em dois tópicos diferentes ?? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
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