UPDATE THE EMAIL VALUE IF EXIT IF EMAIL IS NOT EXIT THEN INSERT NEW EMAIL

Himanshu Rai

Total Post:1

Points:7
Posted by  Himanshu Rai
PHP  MYSQL  SQL 
PHP
 511  View(s)
Ratings:
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....


  1. Sachin Singh

    Post:26

    Points:182
    Re: update the email value if exit if email is not exit then insert new email

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!