autocommit(FALSE); $conn->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); # Inserts into login $sql = "INSERT INTO login (username, hash) VALUES ('".$username."', '".$hash."')"; if($conn->query($sql) === FALSE){ $conn->rollback(); $conn->close(); header("500 Internal Server Error", true, 500); exit(); } # Grabs all data $userid = $conn->insert_id; $nombre = $json["nombre"]; $organizacion = $json["organizacion"]; $puesto = $json["puesto"]; $urbanizacion = $json["urbanizacion"]; $calle = $json["calle"]; $pueblo = $json["pueblo"]; $cpostal = $json["cpostal"]; $telefono = $json["telefono"]; $correo = $json["correo"]; # Checks if necessary data is empty if(!(strlen($nombre) or strlen($urbanizacion) or strlen($calle) or strlen($pueblo) or strlen($cpostal) or strlen($telefono) or strlen($correo))){ $conn->rollback(); $conn->close(); header("400 Bad Request", true, 400); exit(); } # Inserts into miembros $sql = "INSERT INTO miembros (userid, nombre, organizacion, puesto, urbanizacion, calle, pueblo, cpostal, telefono, correo) VALUES " ."('".$userid."', '".$nombre."', '".$organizacion."', '".$puesto."', '".$urbanizacion. "', '".$calle."', '".$pueblo."', '".$cpostal."', '".$telefono."', '".$correo."')"; if($conn->query($sql) === FALSE){ $conn->rollback(); $conn->close(); header("500 Internal Server Error", true, 500); exit(); } # Commits changes $conn->commit(); $conn->close(); # Returns 200 header("200 OK", true, 200); exit(); } else { header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405); exit(); } ?>