Home > DeveloperSection > Forums > update the email value if exit if email is not exit then insert new email
Himanshu Rai
Himanshu Rai

Total Post:1

Points:7
Posted on    March-06-2016 11:30 PM

 PHP PHP  MYSQL  SQL 
Ratings:


 1 Reply(s)
 284  View(s)
Rate this:
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....




Sachin Singh
Sachin Singh

Total Post:26

Points:182
Posted on    March-08-2016 2:44 AM

I think you need to Change Condition of If case as look like below,  Because if any email are exists in '$res' query then it will be updated, if not then created.

 


if(mysqli_num_rows($res) >= 0))
 {
$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; 
}
else

   $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')"); 
}
}




Modified On Mar-08-2016 02:46:27 AM

Don't want to miss updates? Please click the below button!

Follow MindStick