I need help!!
What I want is when I add a new teacher, it will search the tblteacher_info. If there is already a record of that teacher, it will just update his/her record. If there is no record of that teacher, it will add his/her info in the tblteacher_info.
I have here my codes but it's not working.
$sqlsearch = mysql_query("SELECT * FROM tblteacher_info WHERE Fname='$iFName' AND Mname='$iMName' AND Lname='$iLName'",$open_con);
if(!$sqlsearch)
{
die("Database connection failed:" . mysql_error());
}
while ($row = mysql_fetch_array($sqlsearch))
{
if (($row ['Fname'] == "$iFName") AND ($row['Mname'] == "$iMName") AND ($row['Lname'] =="$iLName"))
{
$i_sqlupdate = mysql_query("UPDATE tblteacher_info SET Fname='$iFName', Mname = '$iMName', Lname = '$iLName', Username ='$username', Password='$password' WHERE Lname = '$iFName' AND Mname ='$iMName' AND Lname = '$iLName' ",$open_con);
if(!$i_sqlupdate)
{
die("Error in saving: ". mysql_error());
}
}
elseif (($row ['Fname'] != "$iFName") AND ($row['Mname'] != "$iMName") AND ($row['Lname'] !="$iLName") )
{
$i_sqlinsert= mysql_query("INSERT INTO tblteacher_info (Teacher_ID, Fname, Mname, Lname, Username, Password) VALUES ('0', '$iFName', '$iMName', '$iLName', '$username', '$password')",$open_con);
if(!$i_sqlinsert)
{
die("Error in saving: ". mysql_error());
}
}
}