Hi, I have a form that allows me to insert comments and a total, however once I delete a comment or total I can no longer re-insert a new total or comment. I simply get : SQL Insertion error: Duplicate entry 'xx for key 'PRIMARY'. I am using the myisam engine. MySQL Server version: 5.1.41
The table consists of 4 fields.
MID : Int (primary autonumber)
EID, : Int
Total, :text
Comment. :text
I have two other tables. Member, primary key is mid (member id) and Event primary key is eid (event ID). I dont think I have them relational though.
This is my insert function for the update causing dupe error.
function insert_me($mid, $eid, $total, $comments) {
$esc_mid = mysql_real_escape_string($mid, $this->conn);
$esc_eid = mysql_real_escape_string($eid, $this->conn);
$esc_total = mysql_real_escape_string($total, $this->conn);
$esc_comments = mysql_real_escape_string($comments, $this->conn);
$sql = "insert into memberevent (mid, eid, total, comments)
values ('{$esc_mid}', '{$esc_eid}', '{$esc_total}', '{$esc_comments}')";
$result = mysql_query($sql, $this->conn);
if (!$result) {
die("SQL Insertion error: " . mysql_error());
} else {
$numofrows = mysql_affected_rows($this->conn);
return $numofrows;
}
}
This is the page side code :
Enter lifter total:<input type="text" name="total" id="total" /><br />
Enter comment:<input type="text" name="comments" id="total"/><br />
<input type="submit" value="Save" />
</form>
<?php
}
else//post it into database
{
$mid = $_POST['mid'];
$eid = $_POST['eid'];
$total = $_POST['total'];
$comments = $_POST['comments'];
$db1 = new dbme();
$db1->openDB();
$numofrows = $db1->insert_me($mid, $eid, $total, $comments);
echo "Success. Number of rows affected:
<strong>{$numofrows}<strong>";
$db1->closeDB();
}
?>