Jump to content

SIMPLE DATABASE SEARCH


rajaahsan

Recommended Posts

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....

 

Link to comment
https://forums.phpfreaks.com/topic/236031-simple-database-search/
Share on other sites

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

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..

 

 

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.