Hi...
I've been working with this code for the last few days. The code does what I need... namely adding a record to a table, but I also need to error check for duplicate records so if someone tries to add a duplicate to the table it gives a message stating that, rather than a mysql error.
I've been trying to come up with an error checking and have had no success at all with it. My code for the record insertion is below... any help would be greatly appreciated.
<?
// Create variables //
$add_record = $_POST['username'];
$user = "USERNAME";
$password = "PASSWORD";
$database = "DATABASE";
$table = "TABLE";
if ($add_record == "") {
// header("Location: index.php");
echo "<p align=left>No Data in delete_record string.</p>";
exit;
} else {
// Open connection to database //
$connection = mysql_connect('localhost', $user, $password) or die(mysql_error());
$sql = mysql_select_db($database, $connection) or die(mysql_error());
// Set up query statement //
$add_query = "INSERT INTO $table (pilot) VALUES ('$_POST[username]')";
// Run query and get affected rows //
$addresult = mysql_query($add_query, $connection) or die(mysql_error());
// Run completed statement //
$addpilot_msg = "
<p align=center> </p>
<p align=center><font size=4><b>Pilot added Successfully!</b></font></p>
<p align=center> </p>
<p align=center> </p>
<p align=center><b>Click below to return to Administration page.</b></p>
<p align=center> </p>
<p align=center> </p>
<p align=center><b><a href=index.php>BACK TO STAB INDEX</a></b></p>
<p align=center> </p>";
}
?>