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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.