I have a table called Users
and it has three columns Email , FB_Id , Google_ID
The question is how I can replicate following idea into just one MySQL query.
- Suppose someone login with FB_id then I should check in the DB if the email exist. If yes then update the related ID in this case FB_Id.
What I am trying to do is to keep all the id from different provider for a user. If a user has same user ID for google+ and Fb then we can have ID of both the provider for that email and my website will allow to login it in
The function that I have written is something Like this. Now I want to add the UPDATE
action into this and then get the user details form the DB.
Function
function checkUpdate () {
if ($this->email)
{
$query =" SELECT * FROM `users` WHERE `Email` ='".$this->email."'";
}
else
{
echo "Email not exist ";
}
$rc = $this->parent->database->query($query);
if (mysql_num_rows($rc)>0)
{
$this->flag_details = 'true';
}
while ($rfg=mysql_fetch_array($rc))
{
//print_r($rfg);
$_POST['im_password'] = $rfg['Password'];
$_POST['im_user'] = $rfg['Email'];
}
}
Update1.
function checkUpdate () {
if ($this->email)
{
$query =" SELECT * FROM `users` WHERE `Email` ='".$this->email."'";
}
else
{
echo "Email not exist ";
}
$rc = $this->parent->database->query($query);
if (mysql_num_rows($rc)>0)
{
$this->flag_details = 'true';
//Here is my logic for it which I want to make in one sql query
if (isset($_POST['im_FbId']))
{
$sql = "UPDATE `users` SET fb_id='".$_POST['im_FbId']."' WHERE id=2";
}
if (isset($_POST['im_GId']))
{
$sql = "UPDATE `users` SET google_Id='".$_POST['im_GId']."' WHERE id=2";
}
$this->parent->database->query($sql);
}
while ($rfg=mysql_fetch_array($rc))
{
//print_r($rfg);
$_POST['im_password'] = $rfg['Password'];
$_POST['im_user'] = $rfg['Email'];
}
}
Thanks in Advance