Transaction and handling an error

the code below is a transaction where 2 inserts are made as part of the user registration procedure:

      $result1 =$connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')");
      $result2=$connection->query("insert into  business_users values('".$connection->insert_id."','".$address."' , '".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')");


                            return false;


As you see if the transaction fails false is returned. Nonetheless, if there is a failure in the user registration process I need to have more info regarding that failure.
Returning false, I do not think is enough…what to do…use exception?

You’ll want to use an exception and you’ll want to log the queries in a transaction that run ok, and which was the one that failed and the error given. What database extension are you using (mysqli_*, PDO, etc)?

How am I going to log the queries and check also specifically which failed?
I am using MySqli.

How exactly am I going to implement the exception in this specific case? I know exceptions only in theory

And last but not least.

Is the logging going to help me in knowing the details of the user who failed to register?
Do I have to make it manually?

What happens in these cases?