rajaahsan Posted May 10, 2011 Share Posted May 10, 2011 i have enters some data using form which submit data in sql table1 like this, Fields name in table -->> id First name Lastname Date data saved -->> 1 user 1 2011-05-10 2 user 2 2011-05-11 3 user 3 2011-05-12 now i dont want to duplicate date in database let say while inserting data using form, Firstname : ____________ Lasename : ____________ Date : ____________ (i dont want this date to b save if the date alredy exist in database, it should prompt user "Date already exist and to edit click here (this will be the link to that date which is already exist so that we can edit) " ) SAVE i user files , form.php , insert.php(so insert values in database) , so tell me what function should i use to solve my problem.... Quote Link to comment https://forums.phpfreaks.com/topic/236031-simple-database-search/ Share on other sites More sharing options...
fugix Posted May 10, 2011 Share Posted May 10, 2011 just use a simple if else statement $sql1 = "select * from table_name"; $query1 = mysql_query($sql1) or die(mysql_error()); while($row = mysql_fetch_assoc($query1)) { if($_POST['date'] == $row['date']) { $date = $_POST['date']; $sql = "insert into table_name values ('', '$firstname', '$lastname', '$date')"; $query = mysql_query($sql) or die(mysql_error()); } else { echo "Date already Exists"; } } will need tweaked but thats just to give you an idea Quote Link to comment https://forums.phpfreaks.com/topic/236031-simple-database-search/#findComment-1213428 Share on other sites More sharing options...
rajaahsan Posted May 11, 2011 Author Share Posted May 11, 2011 thanks for your sweet help but now when i use, while { it repeats the same code again and again here....! i am confused here because i need to search only from database that the date selected by user exist already or not if it exist already then data must not be save in database.. } Quote Link to comment https://forums.phpfreaks.com/topic/236031-simple-database-search/#findComment-1213631 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.