I have the following code which posts from the form to the database by saving what is typed into the form. This works but i would like to know how can i be able to check if the record i am entering already exists before adding it as a dublicate and coursing an error. In this case it should be checking if the student_id already exists. If it exists it should echo (record already exists)
$error1='Add New Intern ';
$error0='No error';
if(isset($_POST['btnaddint']))
{
$student_id = trim($_POST['student_id']);
$comp_name = trim($_POST['comp_name']);
$comp_supervisor = trim($_POST['comp_supervisor']);
$comp_tel = trim($_POST['comp_tel']);
$comp_address = trim($_POST['comp_address']);
$comp_city = trim($_POST['comp_city']);
$intake_date = trim($_POST['intake_date']);
$ass_status = trim($_POST['ass_status']);
if($student_id == '' || $comp_name == '' || $comp_supervisor == '' || $comp_tel == '' || $comp_address == '' || $comp_city == '' || $intake_date == '' || $ass_status == '')
{
$error1=" ERROR - Please make sure all required fields are filled ";
}
else
{
require("server/db.php");
$tbl_name="int_company"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$student = mysql_query("INSERT INTO $tbl_name (student_id, comp_name, comp_supervisor, comp_tel, comp_address, comp_city, intake_date, ass_status) VALUES('".$student_id."','".$comp_name."','".$comp_supervisor."','".$comp_tel."','".$comp_address."','".$comp_city."','".$intake_date."','".$ass_status."')") or die("Query failed:4 ".mysql_error());
$error1=" Record has been added... ";
}
}