Help with creating a php record and insert in database

1

I do not understand much about this, but what I'm doing is an android project.

Create a login with facebook, which leads to a user registry, in which only the users enter a user, and the rest of the data I subtract from the profile.

The function you create is called functions.php , which is the next file.

<?php 
header( 'Content-Type: text/html;charset=utf-8' );


function ejecutarSQLCommand($commando){

  $mysqli = new mysqli("*******", "*******", "*******", "******");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

if ( $mysqli->multi_query($commando)) {
     if ($resultset = $mysqli->store_result()) {
        while ($row = $resultset->fetch_array(MYSQLI_BOTH)) {

        }
        $resultset->free();
     }


}



$mysqli->close();
}

function getSQLResultSet($commando){


  $mysqli = new mysqli("******", "*******", "*******", "******");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

if ( $mysqli->multi_query($commando)) {
    return $mysqli->store_result();




}



$mysqli->close();
}


?>

And then create this file called registro.php

<?php include ('functions.php');
$nombre=$_GET['nombre'];
$usuario=$_GET['usuario'];
$mail=$_GET['mail'];
$facebookid=$_GET['facebookid'];


ejecutarSQLCommand("INSERT INTO  'usuarios' (nombre, usuario, mail, facebookid)
VALUES (
'$nombre' ,
'$usuario' ,
'$mail' ,
'$facebookid')

 ON DUPLICATE KEY UPDATE 'nombre'= '$nombre',
'usuario'='$usuario',
'mail'='$mail',
'facebookid'='$facebookid';");

 ?>

The issue is that when I write the url ex:

mydomain.com/folder/register.php?name=loose & user = rattle & mail = [email protected] & facebookid = 254453

is sent to the database, but many records are created.

After 3 attempts I noticed an error in the faecbookid and a complete column could arrive, but that did not solve the problem that many tables were created. if I could correct the .php I would appreciate it !! and if they explain to me how I can delete all those failed records, or the table I would also appreciate them!

    
asked by Mathias Toledo 31.12.2016 в 07:47
source

1 answer

0

Inside your functions.php file where it says if ($ mysqli-> multi_query ($ commando)) { replaced by:

if ( $mysqli->query($commando)) {

To delete all records from your user table:

Delete FROM usuarios;

To delete your users table:

DROP TABLE usuarios;

You are already going to insert one record at a time per GET call. I would recommend that you have a general connection function so that you are not copying for each function you are using.

    
answered by 31.12.2016 / 14:29
source