Passing a value back from PHP Method

Good afternoon,

I am new to script case and have been doing lost of video watching and looking at a lot of examples but I am stumped and cannot seem to figure this one out.
In looking at the Scriptcase 9 example of the help desk.
On the form_customer_open_ticket there is an onBeforeInsert event:

{ticketid} = generate_ticket();

That php method sends values to the ticket table from the above mention form that uses the ticket message table.
The last line gets the ticket id and sends it back to the form

$sql_get_ticketid = "select ticketid from ticket where ticketdate = ".sc_sql_protect($v_ticketdate, ‘date’);
sc_lookup(ret, $sql_get_ticketid);
return({ret[0][0]});

Now I am using some of this as an example and have my own form that everything seems to work when I run the SQL commands on my database.
The difference in my form is that in the onBeforeInsert I have this:

{idticket} = new_ticket();

This is because in my ticketdetail table I have an idticket field that is a foreign key to the idticket field in the tickets table

The last portion of my method is this:

$sql_get_ticketid = “select idTicket from asinvdb.tickets where subject = ‘$v_subjectid’)”;
sc_lookup(ret, $sql_get_ticketid);
return({ret[0][0]});

I am trying to get the Primary Key from the ticket table based on the subject of the ticket and use that for the corresponding field in the ticketdetail table

The problem I have is that the two-fold:

  1. The sc_lookup macro documentation I can find mentioned dataset not ret so can someone define what ret is for me?
  2. When I run the form I can a foreign key error:
    Cannot add or update a child row: a foreign key constraint fails (asinvdb.ticketdetail, CONSTRAINT mainTicketID FOREIGN KEY (idticket) REFERENCES tickets (idTicket)
    ON DELETE CASCADE ON UPDATE CASCADE)

I mimicked the foreign key settings in the example database but still am not having any luck.

Any help or pointers in the right direction would be greatly appreciated.