954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

do not repeat values in databse during insertion using php and javascript

hello all, after tried so much now posting here. i have two programs sql.php and form.jsp. i want to do insert values into mssql database from user input form. sql.php is able to insert the values into database. i have connected database using ODBC.form.jsp is able to give user input form where user can enter name.

when i submit the name it will successfully stored into the database. but if i submit the same name also it will get stored. i don't want store same name twice in the database.and it should notify the user that name already exist in the database. i can't change my database schema to unique constraint.
i need to accomplish throgh program. how to give this validation ?


sql.php

$connect = odbc_connect('SerDB','sa', 'pwd');
      echo "server connected";
     $query=("INSERT INTO namemb(name) VALUES ('$_POST[name]')");
      $result = odbc_exec($connect, $query);


form.jsp

<html>
    <head>
     <script type="text/javascript">
      function validateForm()
   {

        var y=document.forms["myForm"]["name"].value;
      if (y==null || y=="")
       {
    alert("Name must be filled out");
    return false;
      }
     }
    </script>
     </head>

       <body>
     <form name="myForm" action="sql.php" onsubmit="return validateForm()"   
      method="post">
       Name:<input type="text" name="name">
    <br/><br/><br/>
         <input type="submit" value="Submit">
      <input type="button" onclick="window.close()" value="Cancel">
        </form>
       </body>

       </html>
manjushreekaran
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Have you solved? You need to build a callback script, where you check if the value is already stored or not. In order to speed up you can build an index related to that column. Bye.

cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: