Don't Allow Duplicated messages
This commit is contained in:
parent
0ee662067d
commit
14ba3f05c8
|
@ -75,24 +75,37 @@ function setupdb($dbh) {
|
||||||
)');
|
)');
|
||||||
}
|
}
|
||||||
# Adding an Item
|
# Adding an Item
|
||||||
function additem($ndata, $dbh) {
|
function additem($ndata, $dbh, $newURL) {
|
||||||
|
## Check for Duplicates
|
||||||
|
$dupmessagech = "SELECT count(*) FROM messages where message='$ndata->message'";
|
||||||
|
$dupmessage = $dbh->query($dupmessagech)->fetchColumn();
|
||||||
|
|
||||||
|
if($dupmessage > 0) {
|
||||||
|
echo "Another message with this text already exists";
|
||||||
|
header('Refresh:2; url=' . $newURL );
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
$sql = 'INSERT INTO messages
|
$sql = 'INSERT INTO messages
|
||||||
(id, name, date, message, mlength, nlength)
|
(id, name, date, message, mlength, nlength)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)';
|
VALUES (?, ?, ?, ?, ?, ?)';
|
||||||
$sth = $dbh->prepare($sql);
|
$sth = $dbh->prepare($sql);
|
||||||
$sth->execute(array(
|
$sth->execute(array(
|
||||||
null->id,
|
null,
|
||||||
$ndata->name,
|
$ndata->name,
|
||||||
$ndata->date,
|
$ndata->date,
|
||||||
$ndata->message,
|
$ndata->message,
|
||||||
$ndata->mlength,
|
$ndata->mlength,
|
||||||
$ndata->nlength
|
$ndata->nlength
|
||||||
));
|
));
|
||||||
|
header('Refresh:2; url=' . $newURL );
|
||||||
|
echo "Your submisson has been added";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# Setup the Database (If table does not already exist)
|
# Setup the Database (If table does not already exist)
|
||||||
setupdb($dbh);
|
setupdb($dbh);
|
||||||
|
|
||||||
# Add the Item
|
# Add the Item
|
||||||
additem($ndata, $dbh);
|
additem($ndata, $dbh, $newURL);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue