Jump to content
Fórum Script Brasil
  • 0

Verifica Se Arquivo já Existe No Db


Guest --Pablo --
 Share

Question

Guest --Pablo --

Pessoal to precisandu duma ajudinha, sei que tem muitos cracks por aki..... pois bem o codigo abaixo insere um registro no db, gostaria de saber se existe alguma forma na hora que for preencher os campos se o registro já existe avisar com um window alert por exemplo "já cadastrado" ?

Obrigado

<%
option explicit
dim useraction
dim dsn,sql,conn,rs
dim fname,lname,tel
useraction=request("action")
select case useraction
case "add"
    fname=request.form("fname")
    lname=request.form("lname")
    tel=request.form("tel")
    sql = "insert into users (lname,fname,tel) values('"&lname&"','"&fname&"','"&tel&"')"
    dsn="DBQ=" & Server.Mappath("db/mydb.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
    set conn=server.createObject("adodb.connection")
    conn.open dsn
    conn.execute(sql)
    conn.close
    set conn = nothing
    response.write "Registro gravado com sucesso!"
end select
%>
    

<html>
<head>
&lt;script>
function valid(){
var fname = document.addform.fname.value;
var lname = document.addform.lname.value;
var tel = document.addform.tel.value;
if (fname=="" || lname=="" || tel==""){
    alert ("Todos Campos são Obrigatórios")
    return false
    }
if (isNaN(lname)) { 
  alert("Digite Números no Campo Nº")
  return false
      }
}
</script>
    <title>Inserir Telefone</title>
<link rel=stylesheet href="css/08.css">
</head>

<body>
<div align="center">
  <!--#include file="footer.inc"-->
</div>
<form name="addform" action="add.asp?action=add" method="post" onsubmit="return valid()" >
  <table border=0 width=201 align="center">
    <tr> 
      <td colspan=2 align=center><b> Add</b>
    </tr>
    <tr> 
      <td width="71"> Nº:</td>
      <td width="120"><input type="text" name="lname" size=20 maxlength="40"></tr>
    <tr> 
      <td> Endereço:</td>
      <td><input type="text" name="fname" size=20 maxlength="40"></tr>
    <tr> 
      <td> Referência:</td>
      <td><input type="text" name="tel" size=20 maxlength="40"></tr>
    <tr> 
      <td colspan=2 align="center"><div align="right">
          <input name="submit" type="submit" value="Inserir">
        </div></tr>
  </table>
  <div align="center"> </div>
  <font color="#0066CC"></font>
</form>

<p> </p>
<div align="center"> </div>
</body>
</html>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Veja este tópico: http://scriptbrasil.com.br/forum/index.php...st&p=380851

Voce vai aplicar a mesma ideia nesta parte em vermelho do trecho do teu codigo:

fname=request.form("fname")

lname=request.form("lname")

tel=request.form("tel")

'INSIRA O CODIGO AQUI, ANTES DE FAZER O INSERT

sql = "insert into users (lname,fname,tel) values('"&lname&"','"&fname&"','"&tel&"')"

dsn="DBQ=" & Server.Mappath("db/mydb.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

set conn=server.createObject("adodb.connection")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...