Why is my MySQL table inserting 2 identical rows for every 1 inserted row?

For some reason, whenever I insert a row of data to my table, it creates an extra row with the same data.
I’ve been searching, and I’ve observed that you cannot use a “LIMIT 1” keyword in an INSERT statement and
that you can only limit a select statement. Here’s my code:

[php]

try

{

$conn = new PDO(“mysql:dbname=users;host=localhost”, “", "*” );

$sql = $conn->prepare(“INSERT INTO Members (Studentid, Courseid, Teacherid, FirstName, MiddleName, LastName) VALUES (?, ?, ?, ?, ?, ?)”);

$sql->execute(array($_POST[“name”], $class, $teacher, $_POST[“thefname”], $_POST[“themname”], $_POST[“thelname”]));

$sql->execute();

}

catch(PDOException $e)

{

echo $e->getMessage();

$conn = null;

}


And for the Members Table:

±-----------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±-----------±------------±-----±----±--------±------+
| Studentid | varchar(50) | NO | | NULL | |
| Courseid | varchar(50) | NO | | NULL | |
| Teacherid | varchar(50) | NO | | NULL | |
| FirstName | varchar(25) | NO | | NULL | |
| MiddleName | varchar(25) | NO | | NULL | |
| LastName | varchar(25) | NO | | NULL | |
±-----------±------------±-----±----±--------±------+

[/php]

What am I doing to make MySQL create 2 rows instead of one every time? thanks so much everyone

ok honestly I do not code with pdo but I think you could try commenting out one of the executes and see if that fixes the issue

[php]
try
{
$conn = new PDO(“mysql:dbname=users;host=localhost”, “", "*” );
$sql = $conn->prepare(“INSERT INTO Members (Studentid, Courseid, Teacherid, FirstName, MiddleName, LastName) VALUES (?, ?, ?, ?, ?, ?)”);

$sql->execute(array($_POST[“name”], $class, $teacher, $_POST[“thefname”], $_POST[“themname”], $_POST[“thelname”]));
//$sql->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
$conn = null;

}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service