I have these codes for the insertion of data into mysql database in php, unfortunately when I insert the data into the database they are duplicated. Any suggestion on what could be wrong with the codes.
<?php
// create short variable names
$Database=$HTTP_POST_VARS['Database'];
$Publication_Date=$HTTP_POST_VARS['Publication_Date'];
$Title=$HTTP_POST_VARS['Title'];
$Write_Up=$HTTP_POST_VARS['Publication'];
if (!$Publication_Date || !$Title || !$Write_Up)
{
echo '<h4>You have not entered all the required details.<br /></h4>';
echo '<h4>Please go back and try again.</h4>';
exit;
}
$Publication_Date = addslashes($Publication_Date);
$Title = addslashes($Title);
$Write_Up = addslashes($Write_Up);
include 'dbconnect.inc';
$query = "INSERT INTO $Database (Publication_Date, Title, Write_Up) ".
"VALUES ('$Publication_Date', '$Title', '$Write_Up')";
mysql_query($query) or die('Error, query failed');
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows().' Write-Up inserted into database.';
?>
I added this to correct the duplication before inserting anything into the database, but when I insert data, I find nothing in the database.
$query = "select Title from $Database where Title = '$Title'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
{
echo '<p>This article is already in the database. Thanks.</p>';
exit;
}