Avoid duplicate entries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trochia
    New Member
    • Oct 2008
    • 19

    Avoid duplicate entries

    Moderator: thread has been split from http://bytes.com/forum/thread833623.html.

    _______________ _______________ _______________ ____


    Hello Dhiru1009, Marus, Coolsti & Nomad

    I am new to this site as of just now, and ran across it while I was doing a search. And it's one of the most "recent" (as for posting dates ) I have run across, so I would suspect people still visit this forum.

    This is going to the snippet I need to use, (post above) but I am fairly new to php...and can work my way around existing code...and can do small routines.

    I am "cheating"...(l augh) and am using :

    Download phpFormGenerator for free. phpFormGenerator is a tool for creating reliable, efficient, and aesthetically pleasing web forms in a snap. It generates the HTML code, the form processor code (PHP), and the validation code automatically via an easy, point-and-click interface.


    to create my forms that I need.

    I am not sure where I would use this please? I would suspect that I could call this file as an include just as the user presses "Enter"...b ut I am usure where to put it please?

    I have code snippets of the above to show...if needed, and any help will be greatly appreciated.

    Thank's to all, in advnace.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    The code snippet I posted would be used when a form (using POST) is submitted to a page.

    Comment

    • trochia
      New Member
      • Oct 2008
      • 19

      #3
      Thnak-you for the reply, I have sent a PM to you (sorry)...and sorry for my late reply, but I did not, nor have got a e-mail ( and it is selected) for getting a reply from this topic.

      Jim

      Comment

      • trochia
        New Member
        • Oct 2008
        • 19

        #4
        Mello Markus, and all on this site.

        I have found a code snippet of what I need here on this site, and not sure where or how to implement it for sure. I am fairly new to pphp/myql myself.



        And I used a program called : http://phpformgen.sourceforge.net/ to create my form I need to check for duplicates, prior to db entry.

        Below is what the formgen program generates for code, would I just make the file an include? Or put it in here some how?

        A main html file and one called process.php (below)

        I plan on using the phone number field

        Any help greatly appreciated,

        Thx...jim


        ----------[code=php]
        <?php
        include("global .inc.php");
        $errors=0;
        $error="The following errors occured while processing your form input.<ul>";
        pt_register('PO ST','Type');
        pt_register('PO ST','Name');
        pt_register('PO ST','Address');
        pt_register('PO ST','City');
        pt_register('PO ST','State');
        pt_register('PO ST','Zip');
        pt_register('PO ST','Phone');
        pt_register('PO ST','EmailExist s');
        pt_register('PO ST','EmailAddre ss');
        pt_register('PO ST','Website');
        if($Type=="" || $Name=="" || $Address=="" || $City=="" || $State=="" || $Zip=="" || $Phone=="" || $EmailExists==" " ){
        $errors=1;
        $error.="<li>Yo u did not enter one or more of the required fields. Please go back and try again.";
        }
        if($errors==1) echo $error;
        else{
        $where_form_is= "http".($HTTP_S ERVER_VARS["HTTPS"]=="on"?"s":""). "://".$SERVER_NAME. strrev(strstr(s trrev($PHP_SELF ),"/"));
        $message="Type: ".$Type."
        Name: ".$Name."
        Address: ".$Address. "
        City: ".$City."
        State: ".$State."
        Zip: ".$Zip."
        Phone: ".$Phone."
        Email Exists: ".$EmailExists. "
        Email Address: ".$EmailAddress ."
        Website: ".$Website. "
        ";
        $message = stripslashes($m essage);
        mail("jim@james jcotton.com","F orm Submitted at your website",$messa ge,"From: phpFormGenerato r");
        $link = mysql_connect(" localhost","db_ name","dbpass") ;
        mysql_select_db ("emp_skylos",$ link);
        $query="insert into skylos (Type,Name,Addr ess,City,State, Zip,Phone,Email _Exis ts,Email_Addres s,Website) values ('".$Type."','" .$Name."','".$A ddress."','".$C ity."','".$Stat e."','".$Zip."' ,'".$Phone."',' ".$EmailExists. "','".$EmailAdd ress."','".$Web site."')";
        mysql_query($qu ery);
        $make=fopen("ad min/data.dat","a");
        $to_put="";
        $to_put .= $Type."|".$Name ."|".$Address." |".$City."|".$S tate."|".$Zip." |".$Phone."|".$ EmailExists."|" .$EmailAddress. "|".$Websit e."
        ";
        fwrite($make,$t o_put);
        ?>


        <!-- This is the content of the Thank you page, be careful while changing it -->

        <h2>Thank you!</h2>

        <table width=50%>
        <tr><td>Type: </td><td> <?php echo $Type; ?> </td></tr>
        <tr><td>Name: </td><td> <?php echo $Name; ?> </td></tr>
        <tr><td>Address : </td><td> <?php echo $Address; ?> </td></tr>
        <tr><td>City: </td><td> <?php echo $City; ?> </td></tr>
        <tr><td>State : </td><td> <?php echo $State; ?> </td></tr>
        <tr><td>Zip: </td><td> <?php echo $Zip; ?> </td></tr>
        <tr><td>Phone : </td><td> <?php echo $Phone; ?> </td></tr>
        <tr><td>Email Exists: </td><td> <?php echo $EmailExists; ?> </td></tr>
        <tr><td>Email Address: </td><td> <?php echo $EmailAddress; ?> </td></tr>
        <tr><td>Website : </td><td> <?php echo $Website; ?> </td></tr>
        </table>
        <!-- Do not change anything below this line -->

        <?php
        }
        ?>[/code]
        Last edited by pbmods; Oct 5 '08, 06:53 PM. Reason: Added CODE tags.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Right, I'm back to help!

          So, we're trying to catch a duplicate entry? Right.

          I explained everything in the other thread, and it looks like I'm going to be explaining it again. Sigh! Doesn't matter, it shall be done.

          Using a function called mysql_num_rows( ) we can find out how many rows in a mysql table matched the query we ran.

          Here's the modified version of your code:


          Code:
          $rows = mysql_query("SELECT * FROM `skylos` WHERE `col1` = '{$data}'");
          if( mysql_num_rows( $rows ) > 0 )
          {
          	echo "Duplicate entry detected";
          }
          else
          {
          	$query="
          	insert into `skylos` 
          		(Type, Name, Address, City, State, Zip, Phone, Email_Exists, Email_Address, Website)
          			values 
          		(
          			'$Type','$Name','$Address','$City','$State',
          			'$Zip','$Phone','$EmailExists','$EmailAddress','$Website')
          		";
          	mysql_query($query);
          }
          You'll have to edit the $rows query so that you comparing the right field against the right data.

          Cheers,
          Markus.

          Comment

          Working...