I have this HTML FORM
<form action="check_record.php" method="post"> <input type="text" placeholder=""Last Name" name="lname"></input> <input type="text" placeholder=""First Name" name="fname"></input> SUBMIT or CLEAR </form>
once the user submits the form I point it to the check_record.php to check if the record already exist or not
<?php //check_record.php session_start(); $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("web", $connection); $sql="SELECT * FROM `web`.`tbl_student` WHERE lname = '".$_POST["lname].'", fname = '".$_POST["fname"]."' $result = mysql_query($sql); $row = (I forgot the next codes :\) header("Location:add_record.php"); ?>
<?php //add_record.php session_start(); $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("web", $connection); $sql="INSERT INTO `web`.`tbl_student` (`lname`, `fname`) VALUES ('".$_POST["lname].'", '".$_POST["fname"]."')"; $result = mysql_query($sql); header("Location:index.php"); ?>
I am totally new to PHP, my problem here is, once the user submits the form, it will check if the last name or the first name already exist, if it exist it will not allow to add the record and displays a message "Record alreadys exist" if it's not an existing record, it will display a message saying "Record saved." I have no problem with adding, updating, or deleting a record. During our lab activity I figured out how to check if the record already exist but I'm not sure about because after the record has been check and it's not existing it will add though but the last name and the first name are blank :/ please help