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