dimanche 26 avril 2015

If else in sql insert

hye guys...i need your help to solve my problem.....i want to make a code where if the data already exists in the database...and the user insert the same input again and send to the database, the sql command will detect it and will not allow the duplicate data enter the databse.....addtional information : don`t have primary key for my table..here is my code

$sql="INSERT IGNORE INTO tempahan(Nama,Aktiviti,No_HP,Unit,Tempat,Tarikh_Penggunaan,Masa_Mula,Masa_Akhir,Email) VALUES('$_POST[name]','$_POST[Aktiviti]','$_POST[number]','$_POST[unit]','$_POST[tempat]','$_POST[tarikh]','$_POST[masa1]','$_POST[masa2]','$_POST[email]')";

       $_POST['tempat'] = $data['Tempat'] ;
       $_POST['masa1'] = $data['Masa_Mula']; 
       $_POST['masa2'] = $data['Masa_Akhir'];  if($_POST['tempat'] != $data['Tempat'] && $_POST['masa1'] != $data['Masa_Mula'] && $_POST['masa2'] != $data['Masa_Akhir']) {
         echo 'the booking was successful.';
         }
         else
         { echo 'the place already occupied.';}

im new to this sql and also php....therefore i really need help from all of you guys....i already see the other same question like me before asking..but every solution provided i`ve failed...

Aucun commentaire:

Enregistrer un commentaire