代码之家  ›  专栏  ›  技术社区  ›  sanoj lawrence

无法在php中使用ajax发布google onSignIn数据

  •  0
  • sanoj lawrence  · 技术社区  · 6 年前

    onSignIn

    DB 在web服务器中。当我可以在本地主机中插入数据时。

    在web服务器中,我可以在中查看登录详细信息 log.console 但我不能 $_POST PHP

    脚本

             function onSignIn(googleUser) {
                var profile = googleUser.getBasicProfile();
                if (profile) {
                    $.ajax({
                        type: 'POST',
                        url: 'social.php',
                        data: {
                            name: profile.getName(),
                            mail: profile.getEmail(),
                            img: profile.getImageUrl()
                        }
                    }).done(function (data) {
                        console.log(profile.getName());
                        console.log(profile.getEmail());
                        console.log(profile.getImageUrl());
    
                    }).fail(function () {
                        alert("Something went wrong !!");
                    });
                }
            }
    

    菲律宾比索

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    include("$_SERVER[DOCUMENT_ROOT]/include/config.php");
    
    $_SESSION["name"] = $_POST['name'];
    $_SESSION["email"] = $_POST['mail'];
    $_SESSION["img"] = $_POST['img'];
    
    $email = strip_tags($_POST['mail']);
    // The request is using the POST method
    
    $stmt = $conn->prepare("SELECT * FROM sociall WHERE email=:email");
    $stmt->execute(array(':email' => $email));
    $count = $stmt->rowCount();
    
    if ($count > 0) {
        //email used
    } else {
        $stmt = $conn->prepare("INSERT INTO sociall (username, email, socialID, img) VALUES (:username, :email, :socialID, :img)");
        $stmt->bindParam(':username', $_POST['name'], PDO::PARAM_STR, 100);
        $stmt->bindParam(':email', $email, PDO::PARAM_STR, 100);
        $stmt->bindParam(':img', $_POST['img'], PDO::PARAM_STR, 200);
        if ($stmt->execute()) {
    
        }exit;
    }
    

    我也试过了 $_GET 方法,但什么也不做。

    Undefined index: id in C:\Users\Amin\Documents\NetBeansProjects\OLX\ads\login\social.php on line 8
    Undefined index: name in C:\Users\Amin\Documents\NetBeansProjects\OLX\ads\login\social.php on line 9 
    Undefined index: mail in C:\Users\Amin\Documents\NetBeansProjects\OLX\ads\login\social.php on line 10
    Undefined index: img in C:\Users\Amin\Documents\NetBeansProjects\OLX\ads\login\social.php on line 11
    Undefined index: mail in C:\Users\Amin\Documents\NetBeansProjects\OLX\ads\login\social.php on line 13
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   user3783243    6 年前

    在jQuery代码中,请使用 method 而不是 type

    method: 'POST',
    

    $_POST 变量。