nandojlle 0 Denunciar post Postado Julho 18, 2005 É possivel fazer uma validação verificando no banco de dados se o valor digitado no formulario, como por exemplo "cnpj" ja existe no banco de dados e caso exista emitir uma msg de erro??? Compartilhar este post Link para o post Compartilhar em outros sites
Mário Monteiro 179 Denunciar post Postado Julho 18, 2005 sim amigo eh possivel...você já tentou algo?? Compartilhar este post Link para o post Compartilhar em outros sites
nandojlle 0 Denunciar post Postado Julho 18, 2005 beleza??? cara ja tentei sim, porem em todos nao tive nem sinal de dar certo... minhas tentativas: 1º - http://www.imasters.com.br/forum/index.php?showtopic=139156 2º - http://www.imasters.com.br/forum/index.php?showtopic=139156 valeu! sim amigo eh possivel... você já tentou algo?? <{POST_SNAPBACK}> Compartilhar este post Link para o post Compartilhar em outros sites
Douglas 6 Denunciar post Postado Julho 18, 2005 É simples, uma condição if resolve.A lógica:Depois que o usuário preencher e enviar, faça uma consulta à sua tabela com um where com o dado qu você quer.Faça uma condição if verificando se a consulta retornou algum resultado, caso seja verdadeiro (retornou algum registro), exiba a mensagem de dado já cadastrado, caso seja falso (nenhum registro encontrado) cadastre o registro normalmente. Compartilhar este post Link para o post Compartilhar em outros sites
nandojlle 0 Denunciar post Postado Julho 18, 2005 pensei nessa logica, mas na pratica nao consegui adaptar no codigo. O dreamweaver gera o codigo de insert junto com a pagina de formulario. olha só: function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO cadastro (cot_empresa, cot_razaosocial, cot_contato, cot_cidade, cot_fone, cot_email, cot_cnpj, cot_rua, cot_numero, cot_cep, cot_obs, cot_data, cot_codproduto, cor_comresp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['nome'], "text"), GetSQLValueString($_POST['razao'], "text"), GetSQLValueString($_POST['contato'], "text"), GetSQLValueString($_POST['cidade'], "text"), GetSQLValueString($_POST['fone'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['CNPJID'], "text"), GetSQLValueString($_POST['rua'], "text"), GetSQLValueString($_POST['numero'], "text"), GetSQLValueString($_POST['comercialresp'], "text"), GetSQLValueString($_POST['cep'], "text"), GetSQLValueString($_POST['obs'], "text"), GetSQLValueString($_POST['hiddenField'], "date"), GetSQLValueString($_POST['comercialresp'], "int")); mysql_select_db($database_corretor, $corretor); $Result1 = mysql_query($insertSQL, $corretor) or die(mysql_error()); $insertGoTo = "orcamentocadcor.php?nv=" . $_SESSION['nv'] . "&id=" . $_SESSION['id'] . ""; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } É simples, uma condição if resolve. A lógica: Depois que o usuário preencher e enviar, faça uma consulta à sua tabela com um where com o dado qu você quer. Faça uma condição if verificando se a consulta retornou algum resultado, caso seja verdadeiro (retornou algum registro), exiba a mensagem de dado já cadastrado, caso seja falso (nenhum registro encontrado) cadastre o registro normalmente. <{POST_SNAPBACK}> Compartilhar este post Link para o post Compartilhar em outros sites