Jump to content

Multiple duplicate database records on submitting a form


robi_7

Recommended Posts

First of all excuse me if this topic is inappropriate in this forum. But I think it's rather a PHP problem.

 

I can't figure out multiple duplicate database records on submitting a form.

 

The database table have two columns:  the first one 'Id' with AUTO_INCREMENT and the second one 'Name'.

 

Here's the php code for database insertion and the form:

------------------------------------------------------------------

 

<?php

 

if($_GET['add_name']){

    $host = *******;

    $user = *******';

    $pass = *******;

    $db = *******;

    $con = mysql_connect($host,$user,$pass) or die;

    mysql_select_db($db,$con);

   

    $name = $_GET['add_name'];

    $sql = "INSERT INTO names (Name) VALUES ('$name')";

    mysql_query($sql);

}

 

?>

 

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">

Your Name:

<input name="add_name" type="text"  />

<input type="submit" value="Submit" />

</form>

 

------------------------------------------------------------------

 

After submitting the form to itself once I have multiple Name entries with different Ids. The curious thing is that with Chrome browser

I get two duplicate records, with Mozilla - three of them.

Seems like mysql_query runs multiple times.

 

It works fine when submitting the form to a separate script and not to itself.

 

Do I miss something? It must be very basic.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.