forum

home / developersection / forums / update the email value if exit if email is not exit then insert new email

update the email value if exit if email is not exit then insert new email

Himanshu Rai 1778 06-Mar-2016
if(!isset($_SESSION['user']))
{
header("Location: ../index.php");
}

$email=$_SESSION['user'];
$res=mysql_query("SELECT * FROM user_businessleads WHERE user_email='$email'");
$row=mysql_fetch_array($res);

  if(isset($_POST['submit']))
  {
       $looking_for = $_POST['looking_for'];
$services = $_POST['services'];
$mybudget = $_POST['mybudget'];
$around = $_POST['around'];
$s_reguirement = $_POST['s_reguirement'];
$chk="";
$email=$_SESSION['user'];  
     foreach($services as $chk1)  
   {  
      $chk .= $chk1.",";
 
}
 if(!empty($email))
 {
  $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')"); 
}
else
$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;
}
}
in this query in my database value is inserting but did not update .
i want that is email id not exit in table which is given first insert after that if it is exit the only updated
plz suggest  me what the changes required in above code....



php php  mysql  sql 
Updated on 08-Mar-2016
Can you answer this question?

Answer

1 Answers

Liked By