2

The code is the following:

if (mysqli_multi_query($conn, $query)) {

    $token = $_POST['token'];

    $query = "
        INSERT INTO _usuarios (
            login_usuario, 
            nombre_usuario, 
            password_usuario, 
            id_perfil, 
            fecha_creacion_usuario, 
            id_usuarioCreate)
        VALUES (
            '$token',
            '$token',
            '$passCreate',
            6,
            NOW(),
            1
        );";

    if ($conn->query($query) === TRUE) 
    {
        echo "User created successfully";
    } 
    else 
    {
        echo "Error creating user: " . $conn->error.$query;
    }
}

Everytime I run the multiquery (which in this case is a very large sql script for a database creation) and I try to execute the INSERT below, I get the same message:

'Table _usuarios doesn't exist'

I believe that it is because the script hasn't finished running by the time I'm trying to do the insert.

Any ideas?

Halayem Anis
  • 7,233
  • 2
  • 18
  • 39
  • 1
    That error means you don't have created the table _usuarios on the selected db, maybe you should verify on your connection that your desired db is selected. – Neobugu Mar 02 '16 at 17:18
  • This is the wrong way to use MySQL and PHP. You are open to SQL injections. Use PDO. – meager Mar 02 '16 at 17:21

2 Answers2

1

Yes, it's possible.

while ($mysqli->next_result());

Run this code after your multi query to make PHP script wait until last query gets executed.

Note that for your second query you should be using prepared statements instead of adding variables in query directly.

Your Common Sense
  • 152,517
  • 33
  • 193
  • 313
-1

Regarding the error message, it seems as if your table has not been created yet. You can do the following in order to have it created in one step:

    $token = $_POST['token'];
    $token1 = $_POST['token1']; // I do not know it exactly anymore how you can retrieve all the POSTS

    SELECT $token, $token1, field3, field4, ... INTO _usuarios 

Now your table will be created and filled at the same time.

Bernd
  • 531
  • 2
  • 6
  • 21