Checking and Inserting Data into a Table

0

Good evening, I'm implementing a very basic facebook login system on my site, the system should capture the user's basic data (id, name and email) and save it to a table and that's where I'm having difficulties, already I ran around many forums on the internet and tested several codes, but nothing is working.

UPDATING

"I solved the problem by inserting the function.php data inside fbconfig.php, probably the code should be very heavy, but for the time being it worked:

fbcongig.php

<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
require 'dbconfig.php'; // Conexão com o Banco

...

    /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
      $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;      
    /* ---- header location after session ----*/

            if ($fbid>"1"){

                $consulta = "SELECT Fuid FROM Users WHERE Fuid='".$fbid."'";
                $check = mysqli_query($con,$consulta);
                $numeros = mysqli_num_rows ($check);

                if ($numeros <= 0){
                    $query = "INSERT INTO Users (Fuid,Ffname,Femail) VALUES";
                    $query .= "('".$fbid."','".$fbfullname."','".$femail."')";
                    $inserir = mysqli_query($con,$query) or die(mysql_error($con));
                }
            }
    //checkuser($fbid,$fbfullname,$femail);
  header("Location: index.php");
} else {
  $loginUrl = $helper->getLoginUrl(array('scope' => 'email, public_profile,user_friends'));
 header("Location: ".$loginUrl);
}
?>
    
asked by anonymous 03.02.2017 / 00:07

1 answer

0

Your connection is outside the scope of the function. So the first Notice.

  

Notice: Undefined variable: con in   /home/profissa/public_html/teste/functions.php on line 8

Put the line below inside the function.

 $con = mysqli_connect('xxxxxxx','xxxxxx','xxxxxxx','xxxxxxx')
 or die('Não foi possível conectar');

OR you leave the connection where it is and can (not very recommended) use the global keyword, putting this code inside the function:

global $con;

About variable scope: link

Take a look at the mysqli_query syntax also link , missing a parameter before the query string:

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

Change rows

mysqli_query("SELECT Fuid FROM Users WHERE Fuid='".$fbid."'"); 

by

mysqli_query($con,"SELECT Fuid FROM Users WHERE Fuid='".$fbid."'"); 

and

mysqli_query($sql,$con)

by

mysqli_query($con, $sql)
    
03.02.2017 / 00:16