How can I enter data into two different tables?

1

I have created a function to insert information into two different tables, but it is displaying an error:

  

You have an error in your SQL syntax; ('mary', 2147483647, 'a' at line 2)

My role is:

function newUser($connect, $name, $reg, $address, $phone, $email, $pass){
    $query = "insert into user(email, password) values('{$email}','{$pass}'); 
              insert into client(name, reg, address, phone) values('{$name}','{$reg}','{$address}','{$phone}')";
    return mysqli_query($connect, $query);
}

When I test the direct query in the bank, it works. :

    
asked by anonymous 14.06.2018 / 04:37

1 answer

0

Use multi_query to do more than one query to Same time. So:

function newUser($connect, $name, $reg, $address, $phone, $email, $pass){
    $query = "insert into user(email, password) values('{$email}','{$pass}'); 
              insert into client(name, reg, address, phone) values('{$name}','{$reg}','{$address}','{$phone}')";

    return mysqli_multi_query($connect, $query); // aqui será realizado as duas querys
}

This syntax error occurs because you are attempting to perform more than one query using the mysqli_query function.

    
14.06.2018 / 05:58