Don't Allow Duplicated messages

This commit is contained in:
Evan G. 2024-06-10 14:47:35 -05:00
parent 0ee662067d
commit 14ba3f05c8
Signed by: fbievan
GPG Key ID: 55FAB8CB6842F080
1 changed files with 16 additions and 3 deletions

View File

@ -75,24 +75,37 @@ function setupdb($dbh) {
)');
}
# 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
(id, name, date, message, mlength, nlength)
VALUES (?, ?, ?, ?, ?, ?)';
$sth = $dbh->prepare($sql);
$sth->execute(array(
null->id,
null,
$ndata->name,
$ndata->date,
$ndata->message,
$ndata->mlength,
$ndata->nlength
));
header('Refresh:2; url=' . $newURL );
echo "Your submisson has been added";
exit();
}
}
# Setup the Database (If table does not already exist)
setupdb($dbh);
# Add the Item
additem($ndata, $dbh);
additem($ndata, $dbh, $newURL);
?>