joaocasta Posted July 11, 2012 at 09:34 PM Report Share #468406 Posted July 11, 2012 at 09:34 PM (edited) olá volto a este topico para nao abrir outro <?php include "config.php"; include "template.php"; $error = ""; if (!empty($_POST['submit'])) { if (empty($_POST['nomeimdb'])) { $error .= 'NOMEIMDB is empty.<br />'; } if (empty($_POST['nomept'])) { $error .= 'EM FLATA NMEPT.<br />'; } if (empty($error )) { $nomeimdb = mysql_real_escape_string ($_POST['nomeimdb']); $nomept = mysql_real_escape_string ($_POST['nomept']); $capa = mysql_real_escape_string ($_POST['capa']); $release = mysql_real_escape_string ($_POST['release']); $linkimdb = mysql_real_escape_string ($_POST['linkimdb']); $genero = mysql_real_escape_string ($_POST['genero']); $duracao = mysql_real_escape_string ($_POST['duracao']); $ano = mysql_real_escape_string ($_POST['ano']); $idioma = mysql_real_escape_string ($_POST['idioma']); $tamanho = mysql_real_escape_string ($_POST['tamanho']); $screen1 = mysql_real_escape_string ($_POST['screen1']); $screen2 = mysql_real_escape_string ($_POST['screen2']); $screen3 = mysql_real_escape_string ($_POST['screen3']); $elenco = mysql_real_escape_string ($_POST['elenco']); $trailer = mysql_real_escape_string ($_POST['trailer']); $sinopse = mysql_real_escape_string ($_POST['sinopse']); $link1 = mysql_real_escape_string ($_POST['link1']); $submit = $_POST['submit']; //no need to validate this $checkupload = mysql_query("SELECT * FROM downloads WHERE nomeimdb = '".$nomeimdb."'"); $nomeimdb = mysql_real_escape_string($_POST['nomeimdb']); if(mysql_num_rows($checkupload) == 1) { $error .= '<p>Sorry, that movie is taken. Please go back and try again.</p>'; } $id_utilizador = (int)$_SESSION['id']; $dreg = date('Y-m-d H:i:s'); if (empty($error)) { $registerquery = mysql_query("INSERT INTO downloads (id_utilizador, `nomeimdb`, `nomept`, `capa`, `linkimdb`, `genero`, `duracao`, `ano`, `idioma`, `tamanho`, `screen1`, `screen2`, `screen3`, `trailer`, `sinopse`, `elenco`, `link1`, dreg) VALUES(".$id_utilizador.", '$nomeimdb', '$nomept', '$capa', '$linkimdb', '$genero', '$duracao', '$ano', '$idioma', '$tamanho', '$screen1', '$screen2', '$screen3', '$trailer', '$sinopse', '$elenco', '$link1', '$dreg')") or die(mysql_error()); if($registerquery) { $success = "<h1>Success</h1>"; $success .= "<p>Your account was successfully created. Please <a href=\"login.php\">click here to login</a>.</p>"; } else { $error .= "<p>Sorry, your registration failed. Please go back and try again.</p>"; } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registo</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <?php if (!empty($error)) { ?> <h1>Error</h1> <?php echo $error; ?> <?php }elseif (!empty($success)) { echo $success; }else { ?> <style type="text/css"> #formCadastro table { float: left; text-align: right; } #tLeft { border-right: 1px silver solid; margin-right: 10px; padding-right: 10px; } </style> <div id="add" align="center"> <form id="formCadastro" action="#" method="post"> <table id="tLeft"> <tr> <td> Nome IMDb: </td> <td> <input name="nomeimdb" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Nome PT: </td> <td> <input name="nomept" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Capa: </td> <td> <input name="capa" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Release: </td> <td> <input name="release" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Link Imdb: </td> <td> <input name="linkimdb" type="text" class="input" size="25"/> </td> </tr> <tr> <td> <label for="genero">Genero: </td> <td> <input name="genero" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Duracao: </td> <td> <input name="duracao" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Ano: </td> <td> <input name="ano" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Idioma: </td> <td> <input name="idioma" type="text" class="input" size="25"/> </td> </tr> </table> <table> <tr> <td> Tamanho: </td> <td> <input name="tamanho" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Screen 1: </td> <td> <input name="screen1" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Screen 2: </td> <td> <input name="screen2" type="text" class="input"/> </td> </tr> <tr> <td> Screen 3: </td> <td> <input name="screen3" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Trailer: </td> <td> <input name="trailer" type="text" class="input" size="25"/> </td> </tr> <tr> <td> Sinopse: </td> <td> <textarea name="sinopse" type="text" class="input" size="25"><textarea> </td> </tr> <tr> <td> Elenco: </td> <td> <input name="elenco" type="text" class="input" size="25" maxlength="200" /> </td> </tr> <tr> <td> Link: </td> <td> <input name="link1" type="text" class="input" size="25" maxlength="200" /> </td> </tr> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Enviar" /></td> </tr> </table> </form></div> <?php } ?> </div> </body> </html> como posso fazer, como eu tenho 17 campos, mostrar apenas um erro a dizer que "Há Dados Em Falta!".. Como faço isso? Edited July 11, 2012 at 09:37 PM by joaocasta Link to comment Share on other sites More sharing options...
brunoais Posted July 11, 2012 at 09:42 PM Report Share #468407 Posted July 11, 2012 at 09:42 PM @joaocasta Eu sei que querias aproveitar o tópico. Mesmo assim: Um problema, um tópico. Esse problema é suficientemente diferente do outro para serem dois tópicos em separado. "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
laeknishendr Posted July 11, 2012 at 11:10 PM Report Share #468419 Posted July 11, 2012 at 11:10 PM Isso foi o que pensei: <?php function haveNullPost() { foreach( $_POST as $post ) { if($post == "" or $post == null) $dadosFaltando = true; } if(isset($dadosFaltando)) return true; else return false; } if( haveNullPost() ) { echo "Algum campo não foi preenchido..."; } else { /* ... */ } ?> Link to comment Share on other sites More sharing options...
MASNathan Posted July 12, 2012 at 10:42 AM Report Share #468463 Posted July 12, 2012 at 10:42 AM (edited) Isso foi o que pensei: <?php function haveNullPost() { foreach( $_POST as $post ) { if($post == "" or $post == null) $dadosFaltando = true; } if(isset($dadosFaltando)) return true; else return false; } if( haveNullPost() ) { echo "Algum campo não foi preenchido..."; } else { /* ... */ } ?> Boas, tomei a liberdade de melhorar o teu código (ou pelo menos assim o espero) <?php function validateFiels(){ $listFields = func_get_args(); if(count($listFields) == 0){ foreach( $_POST as $key => $value ){ if(!isset($_POST[$key])){ return false; } if(is_null($post) or $post == ""){ return false; } } }else{ foreach( $listFields as $value ){ if(!isset($_POST[$value]) or $_POST[$value] == ""){ return false; } } } return true; } //UTILIZAÇÃO if (validateFiels()){ echo 'Mensagem de erro'; }else{ /**Coisas**/ } /* OU ENTAO */ if (validateFiels('nome','apelido','etc')){ //se não quiseres validar os campos todos echo 'Mensagem de erro'; }else{ /**Coisas**/ } Teoricamente funciona, ainda não testei mas aguardo feedback Edited July 12, 2012 at 10:44 AM by MASNathan Link to comment Share on other sites More sharing options...
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