423,674 Members | 1,946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,674 IT Pros & Developers. It's quick & easy.

insert the email id its not exit; if exit only update the row do not insert again

P: 1
i have table in which first time insert the value in table
and second time when i was login with same email update row did no insert again.
my problem is that when i was my query my table is updated but insert once again the in next row;
i want that only update did not insert again
please solve my problem as soon as possible for you
here i am sending my php code below
Expand|Select|Wrap|Line Numbers
  1. if(!isset($_SESSION['user']))
  2. {
  3.     header("Location: ../index.php");
  4. }
  5.  
  6. $email=$_SESSION['user'];
  7. $res=mysql_query("SELECT * FROM user_businessleads WHERE user_email='$email'");
  8. $row=mysql_fetch_array($res);
  9.  
  10.   if(isset($_POST['submit']))
  11.   {
  12.        $looking_for = $_POST['looking_for'];
  13.         $services = $_POST['services'];
  14.         $mybudget = $_POST['mybudget'];
  15.         $around = $_POST['around'];
  16.         $s_reguirement = $_POST['s_reguirement'];
  17.         $chk="";
  18.     $email=$_SESSION['user'];  
  19.      foreach($services as $chk1)  
  20.    {  
  21.       $chk .= $chk1.",";
  22.  
  23. }
  24.  
  25.        $query=mysql_query("INSERT INTO user_businessleads(services,user_email,looking_for,mybudget,around,s_requirment)values('$chk','$email','$looking_for','$mybudget','$around','$s_reguirement')"); 
  26. }
  27.  if(isset($_POST['submit']))
  28.   {
  29.        $looking_for = $_POST['looking_for'];
  30.         $services = $_POST['services'];
  31.         $mybudget = $_POST['mybudget'];
  32.         $around = $_POST['around'];
  33.         $s_reguirement = $_POST['s_reguirement'];
  34.         $chk="";
  35.     $email=$_SESSION['user'];  
  36.      foreach($services as $chk1)  
  37.    {  
  38.       $chk .= $chk1.",";
  39.  
  40. }
  41.  $updated=mysql_query("UPDATE user_businessleads SET services='$chk',looking_for=' $looking_for',mybudget='$mybudget',around='$around',s_requirment='$s_reguirement' WHERE user_email='$email'")or die;
  42. }
  43. ?>
Mar 7 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.