我有一个名为Users
的表,它有三个列 Email , FB_Id , Google_ID
问题是如何将以下想法复制到一个MySQL查询中。
我要做的是为用户保留来自不同提供商的所有ID。如果用户拥有google +和Fb的相同用户ID,那么我们可以拥有该电子邮件的提供商的ID,我的网站将允许其登录
我写的功能是这样的。现在我想在此添加UPDATE
操作,然后从DB获取用户详细信息。
功能
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'];
}
}
先谢谢
答案 0 :(得分:0)
更新users
SET FB_id =' FACABOOK_FB_ID'在哪里EMAIL =' FB_EMAI';
答案 1 :(得分:0)
如果我正确理解您的问题,您想要同时更新google id和facebook id
<?php
$sql = "UPDATE `users` ";
$sql .= isset($_POST['im_FbId']) ? " SET fb_id='{$_POST['im_FbId']}' " : "";
$comma = isset($_POST['im_FbId']) ? "," : "";
$sql .= isset($_POST['im_GId']) ? " {$comma}SET google_Id='{$_POST['im_GId']}' " : "";
$sql .= " WHERE id=2";
$this->parent->database->query($sql);
如果只存在一个例如$ _POST [&#39; im_FbId&#39;],则$ sql值为
UPDATE `users` SET fb_id='facebook id' WHERE id=2
如果两个Id都存在,则$ sql值将为
UPDATE `users` SET fb_id='facebook id' ,SET google_Id='google id' WHERE id=2