greetings,
i was wondering if anyone can help me out with this:
I have 2 tables in mysql:
1st one that logs an id_ticket and some other information
2nd one that is the actual table where the comments of each ticket are logged.
my problem is this:
when logging a new ticket the id_ticket is generated by mysql auto_incremented in the first table.
at the same time i need that same id in the second table in order to keep the track of the comments that are entered for each ticket id.
I tried this:
$query="INSERT INTO helpdesk (
id_ticket ,
date ,
photo_id ,
status_id ,
assigned ,
problem_id
)
VALUES (
'',
'"."$date"."',
'"."$photoid"."',
'"."$tix_status"."',
'"."$assigned"."',
'"."$problem"."')";
mysql_query("$query");
$query_id = mysql_query("select * from helpdesk where date = $date");
$row_id=mysql_fetch_array($query_id);
$var_ticket=$row_id["id_ticket"];
//echo $var_ticket;
$query2="INSERT INTO comments (
id ,
assigned ,
user_id ,
ticket_id ,
comment ,
date
)
VALUES (
'',
'"."$userid"."',
'"."$user"."',
'"."$var_ticket"."',
'"."$comments"."',
'"."$date"."')";
mysql_query("$query2");
Header('Location: '.$path.'index.php');
I tried echo-ing the $var_ticket after inserting the first part into the first table but get an error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\website\ticket_track_log_new.php
So my questions are:
is there any way to get a hold of that id generated 3 lines of code above to where i'm requesting it????
is there any other (simpler) way of doing this???
Thanks in advance