dadedidhodong Posted August 23, 2013 Share Posted August 23, 2013 (edited) 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 Edited August 23, 2013 by Zane Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 23, 2013 Share Posted August 23, 2013 That code is a car crash. The problem that relates to your question is two part: part one is due to you not having any conditional checking on the header to load the add record page, and part two is that you have no persistence for your variables moving on from the check record page. I don't even know why you have the add record script on a different page anyway, and even if there was a reason for it I can't think why you would redirect to load it rather than just use an include. I'm not even going to get started on the db transaction stuff. Quote Link to comment Share on other sites More sharing options...
Zane Posted August 23, 2013 Share Posted August 23, 2013 $row = (I forgot the next codes :\) $rownum = mysql_num_rows($result); Quote Link to comment Share on other sites More sharing options...
dadedidhodong Posted August 25, 2013 Author Share Posted August 25, 2013 function makePass($word=''){$dbSalt = '$2a$07.substr(hash('whirlpool',$word),0,22);$dbPass = crypt($word, $dbSalt);return substr($dbPass,12);} I'm not sure but I guess this code is for password. My problem is, how can I make the program to prohibit adding records that does exist (i.e. Last Name and First Name). Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2013 Share Posted August 26, 2013 look at my post again. the bit below the grey line is my signature - it apears on all posts I make and is not post specific. the bit above the grey line is my response - it is directly in response to your post. Quote Link to comment Share on other sites More sharing options...
dadedidhodong Posted August 26, 2013 Author Share Posted August 26, 2013 Oh. Sorry. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.