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

Link to comment
Share on other sites

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

 

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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