Insert newly made record into fields with logic hook

I have made a logic hook that lets users update fields for existing contacts directly within an invoice from a relate field, this works very well.
I have also made it so that it adds new contacts to the database if they do not exist! The only problem is once the page is refreshed the relate field is blank and the user has to manually type in the name of the contact that they just created (it does come up though).

What I want to do is finish off the logic hook by making it take the newly created contact record (name and ID) and insert it into those fields.
I have tried something below but it gives me an error.
Any ideas?

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class ContactManagement {
   function CreateContact(& $focus, $bean, $event, $arguments){
      global $current_user, $db;

            $query = "SELECT id FROM contacts WHERE id='".$focus->billing_contact_id."' AND last_name like '".$focus->billing_contact_name_c."';";
            $result = $db->query($query, true,"Error reading tasks entry: ");
            $row = $db->fetchByAssoc($result);
            if($row != null) {
			$taskid = $row['id'];
			$query = "UPDATE contacts SET modified_user_id='".$current_user->id."', department='".$focus->clientcompany_c."', assigned_user_id='".$current_user->id."', date_modified=now(), deleted='0', id='".$focus->billing_contact_id."', description='".$focus->clientaddress_c."', phone_work='".$focus->contactofficephone_c."' WHERE  id='".$taskid."';";   
			$result = $db->query($query, true,"Error updating tasks entry: ");
            } else {
			$query = "INSERT INTO contacts (id, last_name, phone_work, department, description) VALUES (uuid(), '".$focus->billing_contact_name_c."', '".$focus->contactofficephone_c."', '".$focus->clientcompany_c."', '".$focus->clientaddress_c."');";
			$result = $db->query($query, true,"Error setting tasks entry: ");

			$billing_contact = '".$focus->billing_contact."';
	                $billing_contact_id = uuid();

What error do you get?

From my understandind the parameters you put in your class method are not correct.

I always thought that the parameters should be: (&$bean, $event, $arguments), while yours has the following parameters: (& $focus, $bean, $event, $arguments)
This means that you are passing two beans

How did you instruct the software to interpret the parameters in the way you are intending to use them?

In addition you put a space between the & and the $focus variable.

My error was to do with the $bean->save();
The main part I’m focusing on is once the contact record has been created, to insert it into the name and ID fields.
This is what I was trying so far but it’s not making a difference. I think the focus and bean are allowed to be like that, just my method below isn’t working:
The uuid is because the ID is being generated when it’s created I think?

$billing_contact = '".$focus->billing_contact."';
$billing_contact_id = uuid();

I’ve got it very nearly working, the main problem is the ID, as the id is newly generated how do I get it to populate the billing_contact_id in the invoice?

 $query2 = "SELECT id FROM aos_invoices WHERE id='".$focus->id."' AND name like '".$focus->name."';";
            $result2 = $db->query($query2, true,"Error reading tasks entry: ");
            $row2 = $db->fetchByAssoc($result2);
			 if($row2 != null) {
			$updateinvoiceid = $row2['id'];
			$query2 = "UPDATE aos_invoices SET billing_contact='".$focus->billing_contact_name_c."', billing_contact_id='".uuid()."', WHERE  id='".$updateinvoiceid."';";   
			$result2 = $db->query($query2, true,"Error updating tasks entry: ");
            } else {}