AngeloLopes Posted July 19, 2013 at 02:42 PM Report #519371 Posted July 19, 2013 at 02:42 PM (edited) Como se faz uma junção de duas textboxs? por exemplo para o codigo postal, como se junta as duas textboxs numa variavel? eu c# isto ficaria mais ou menos assim : string cpostal = txtcpostal1.text + '-' + txtcpostal2.text; mas aqui em php ou html nao sei :/ alguem me pode ajudar? Edited July 23, 2013 at 09:33 PM by yoda
bioshock Posted July 19, 2013 at 03:49 PM Report #519387 Posted July 19, 2013 at 03:49 PM (edited) $cpostal = $_POST['postal1'] . "-" . $_POST['postal2']; Edited July 19, 2013 at 03:49 PM by bioshock
AngeloLopes Posted July 19, 2013 at 03:53 PM Author Report #519390 Posted July 19, 2013 at 03:53 PM Dá-me este erro : Variable $cpostal seems to be unused in its scope o meu código postal esta assim : <tr> <td>Codigo Postal</td> <td align="left"><input id="input1" type='int' name='cpostal1' maxlength="4" /><label for='cpost' >-</label><input id="input1" type='int' name='cpostal2' maxlength="4" /></td> </tr> e no php está assim: $cpostal = $_POST['cpostal1'] . "-" . $_POST['cpostal2'];
bioshock Posted July 19, 2013 at 04:05 PM Report #519397 Posted July 19, 2013 at 04:05 PM Estás a usar NetBeans?
AngeloLopes Posted July 19, 2013 at 04:17 PM Author Report #519400 Posted July 19, 2013 at 04:17 PM Estás a usar NetBeans? sim estou kkkk
N3lson Posted July 19, 2013 at 05:46 PM Report #519411 Posted July 19, 2013 at 05:46 PM Tenta fazer assim <tr> <td>Codigo Postal</td> <td align="left"> <input id="input1" type='int' name='cpostal1' maxlength="4" />-<input id="input1" type='int' name='cpostal2' maxlength="4" /> </td> </tr> $postal1 = $_POST['postal1']; $postal2 = $_POST['postal2']; $cpostal = $postal1.'-'.$postal2; You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
Rui Carlos Posted July 19, 2013 at 05:47 PM Report #519412 Posted July 19, 2013 at 05:47 PM Dá-me este erro : Variable $cpostal seems to be unused in its scope Isso deve ser apenas um aviso, e não um erro. Rui Carlos Gonçalves
bioshock Posted July 19, 2013 at 05:49 PM Report #519413 Posted July 19, 2013 at 05:49 PM Pelos vistos é um bug do netbeans. http://stackoverflow.com/questions/1803323/warning-variable-does-not-seem-to-be-used-in-its-scope-in-foreach
N3lson Posted July 19, 2013 at 05:52 PM Report #519414 Posted July 19, 2013 at 05:52 PM Uma questão. Como validas o que os utilizadores inserem ? O código postal que estás á espera pode não ser o que colocam. You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
AngeloLopes Posted July 22, 2013 at 11:19 AM Author Report #519549 Posted July 22, 2013 at 11:19 AM Tenta fazer assim <tr> <td>Codigo Postal</td> <td align="left"> <input id="input1" type='int' name='cpostal1' maxlength="4" />-<input id="input1" type='int' name='cpostal2' maxlength="4" /> </td> </tr> $postal1 = $_POST['postal1']; $postal2 = $_POST['postal2']; $cpostal = $postal1.'-'.$postal2; Meti igualzinho ao teu e ja grava, mas qualquer que seja o registo so grava 1-1, nao entendo nao grava o codigo postal que nos introduzimos, introduz sempre 1-1 :/ que se passa?
yoda Posted July 22, 2013 at 01:08 PM Report #519552 Posted July 22, 2013 at 01:08 PM Grava onde? before you post, what have you tried? - http://filipematias.info sense, purpose, direction
AngeloLopes Posted July 22, 2013 at 01:20 PM Author Report #519553 Posted July 22, 2013 at 01:20 PM na base de dados mysql.
yoda Posted July 22, 2013 at 02:23 PM Report #519559 Posted July 22, 2013 at 02:23 PM Então mostra o código relevante, não podemos adivinhar. before you post, what have you tried? - http://filipematias.info sense, purpose, direction
AngeloLopes Posted July 22, 2013 at 03:35 PM Author Report #519566 Posted July 22, 2013 at 03:35 PM <form name="input" method="post"> <div id="formularios"> <div id="fornecedores"> <table id="table"> <tr> <td>Nome da Empresa</td> <td><input id="input" type='text' name='nome_empresa' maxlength="50" />*</td> </tr> <tr> <td>Morada 1</td> <td><input id="input" type='text' name='moradal1' maxlength="50" /></td> </tr> <tr> <td>Morada 2</td> <td><input id="input" type='text' name='moradal2' maxlength="50" /></td> </tr> <tr> <td>Codigo Postal</td> <td align="left"> <input id="input1" type='int' name='cpostal1' maxlength="4" />-<input id="input1" type='int' name='cpostal2' maxlength="3" /> </td> </tr> <tr> <td>Localidade</td> <td><input id="input" type='text' name='localidade' maxlength="50" /></td> </tr> <tr> <td>Pais</td> <td><input id="input" type='text' name='pais' maxlength="50" /></td> </tr> <tr> <td>Telefone</td> <td><input id="input" type='int' name='Telefone' maxlength="14" /></td> </tr> <tr> <td>NIF</td> <td><input id="input" type='int' name='nif' maxlength="9" />*</td> </tr> <tr> <td>Email</td> <td><input id="input" type='text' name='Email' maxlength="50" /></td> </tr> <tr> <td>WebPage</td> <td><input id="input" type='text' name='webpage' maxlength="50" /></td> </tr> <tr> <td>Campos Obrigatórios *</td> </tr> </table> </div> <div id="botoes"> <input type='submit' name='Submit' value='Registar Fornecedor' /> <input type='submit' name='Submit' value='Apagar' /> </div> </div> </form> <?php $cpostal1 = isset($_POST['cpostal1']); $cpostal2 = isset($_POST['cpostal2']); $cpostal = $cpostal1.'-'.$cpostal2; if(isset($_POST['nome_empresa']) && isset($_POST['nif'])) { $con=mysqli_connect("127.0.0.1","root","","gesinf"); // Check connection if (mysqli_connect_errno()) { } $sql="INSERT INTO fornecedor (NomeEmpresa, MoradaL1, MoradaL2, CPostal, Localidade, Pais, Telefone, NIF, Email, WebPage)VALUES('$_POST[nome_empresa]','$_POST[moradal1]','$_POST[moradal2]','$cpostal','$_POST[localidade]','$_POST[pais]','$_POST[Telefone]','$_POST[nif]','$_POST[Email]','$_POST[webpage]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "Registado com sucesso!"; mysqli_close($con); } ?>
N3lson Posted July 23, 2013 at 09:07 PM Report #519704 Posted July 23, 2013 at 09:07 PM Nao coloques int <input id="input1" type='int' name='cpostal1' maxlength="4" />-<input id="input1" type='int' name='cpostal2' maxlength="3" /> coloca text e faz a validação com preg_match <input id="input1" type='text' name='cpostal1' maxlength="4" />-<input id="input1" type='text' name='cpostal2' maxlength="3" /> You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
AngeloLopes Posted July 24, 2013 at 08:29 AM Author Report #519737 Posted July 24, 2013 at 08:29 AM Continua igual :/ http://s6219.abelhas.pt/ChomikImage.aspx?e=b1iQABIrIPr_dy_rgZViNIxXI3B_48B5xxjJRIkUBB41DYUqFtixg3tyQO7ApMl6DHcKYkL1kAwelR6QIBb4kA&pv=1 nao entendo o porque :/
Solution pikax Posted July 24, 2013 at 09:07 AM Solution Report #519750 Posted July 24, 2013 at 09:07 AM Problema esta' aqui: $cpostal1 = isset($_POST['cpostal1']); //estas a atribuir o valor de verdadeiro!!! //$Cpostal1 == a true se existir cpostal1 ou falso se nao existir! $cpostal2 = isset($_POST['cpostal2']); //$Cpostal2 == a true se existir cpostal1 ou falso se nao existir! $cpostal = $cpostal1.'-'.$cpostal2; Correcto: $cpostal1 = isset($_POST['cpostal1'])?$_POST['cpostal1']:""; $cpostal2 = isset($_POST['cpostal2'])?$_POST['cpostal2']:""; $cpostal = $cpostal1.'-'.$cpostal2; 1 Report Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
AngeloLopes Posted July 24, 2013 at 09:32 AM Author Report #519752 Posted July 24, 2013 at 09:32 AM Muito Obrigado Pikax resolveste o meu problema 😉
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