gpt4 book ai didi

php - 向mysql中插入数据

转载 作者:行者123 更新时间:2023-11-30 23:05:38 25 4
gpt4 key购买 nike

我想通过 ID 和电子邮件查看,但下面的代码不起作用,谢谢你帮助我执行了以下步骤

通过 facebook id 验证

  • 如果有 id ==> 更新 BD 并重定向 home.php

  • 如果 id 不存在,我们将检查 BD 上是否存在电子邮件(从 facebook 检索)

  • 如果是==>显示“此邮箱已被使用”

  • 如果不是 ==> 插入数据库并 ==> 重定向到 home.php

    $cont = $idf;

    $idf = $user_profile['id'];

    $email = $user_profile['email'];

    $query = "SELECT idf from users where idf = $idf ";
    $result = mysql_query($query);


    if(mysql_num_rows($result) > 1)


    {
    // row exists. so update

    mysql_query("UPDATE users SET name = '".$name."', birthday = '".$birthday."', gender = '".$gender."', email = '".$email."' WHERE idf = '".$idf."';") or die(mysqli_error());

    header( "refresh:4;url=/home.php" );

    }

    else

    {

    $sql1 = "SELECT * FROM users WHERE email = $email ";
    $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());

    if (mysqli_num_rows($result1) > 0)



    echo "This Email is already used.";

    }

    else


    {

    // row does not exists. so create new
    //insertion dans la base de donnée
    $sql= mysql_query("INSERT INTO users (name, email, birthday, gender,idl,idf ) VALUES ('".$name."', '".$email."', '".$birthday."', '".$gender."',NULL,'".$idf."');");

    //mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());


    //echo 'Le cookie existe ' . $cont . '<br />';

    mysql_close();

    setcookie("cokiz", $cont, time()+3600, "/", "NDD");
    setcookie("cokiz", $cont, time()+3600, "/", "NDD");

    header( "refresh:4;url=/home.php" );


    }
    }


    ?>

最佳答案

    use this this will work i think so , use myl_sqli_query  or  mysql_query

$cont = $idf;

$idf = $user_profile['id'];

$email = $user_profile['email'];

$query = "SELECT idf from users where idf = $idf ";
$result = mysql_query($query);


if(mysql_num_rows($result) > 1)


{
// row exists. so update

mysql_query("UPDATE users SET name = '".$name."', birthday = '".$birthday."', gender = '".$gender."', email = '".$email."' WHERE idf = '".$idf."';") or die(mysqli_error());

header( "refresh:4;url=/home.php" );

}

else

{

$sql1 = "SELECT * FROM users WHERE email = $email ";
$result1 = mysql_query($mysql,$sql1) or die(mysql_error());

if (mysql_num_rows($result1) > 0)



echo "This Email is already used.";

}

else


{

// row does not exists. so create new
//insertion dans la base de donnée
$sql= mysql_query("INSERT INTO users (name, email, birthday, gender,idl,idf ) VALUES ('".$name."', '".$email."', '".$birthday."', '".$gender."',NULL,'".$idf."');");

//mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error());


//echo 'Le cookie existe ' . $cont . '<br />';

mysql_close();

setcookie("cokiz", $cont, time()+3600, "/", "NDD");
setcookie("cokiz", $cont, time()+3600, "/", "NDD");

header( "refresh:4;url=/home.php" );


}
}


?>

关于php - 向mysql中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22019820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com