This topic is locked

Help With Event Custom Code

9/27/2009 10:09:50 PM
PHPRunner General questions
V
vic4nze author

Hi, I'm a newbie and need help with this: I have two tables A and B. I want to update B after inserting a record in A.

Table A: User_id, Group_id ....

Table B: Group_id, .......
global $conn;

$Group_id = $values["Group_id"];

$User_id = $values["User_id"];
$select = "SELECT ... FROM Table_B WHERE ....= $Group_id";
$update1 = "UPDATE Table_B SET ...... ";

$update2 = "UPDATE Table_B SET ...... ";
$insert = "INSERT INTO Table_B( ..., ..., ... ) VALUES( $User_id, ...., .... )";
db_exec($select, $update1, $update2, $insert, $conn);
PROBLEM: From the add page it inserts the new record in Table A but then the ERROR: mysql_query(): supplied argument is not a valid MySQL-Link resource. Please any info on what I'm missing or how I can restructure?

J
Jane 9/28/2009

Hi,
here is the correct format of db_exec function:

db_exec($strSQL,$conn);


db_exec($select, $conn);

db_exec($update1, $conn);

db_exec($update2, $conn);

db_exec($insert, $conn);
V
vic4nze author 9/28/2009



Hi,
here is the correct format of db_exec function:

db_exec($strSQL,$conn);


db_exec($select, $conn);

db_exec($update1, $conn);

db_exec($update2, $conn);

db_exec($insert, $conn);



Hi Jane thanks for pointing this out to me but yet I'm still getting another error "You can't specify target table 'B' for update in FROM clause".

Any suggestions on how I can reconstruct the query?
Thanks

V
vic4nze author 9/28/2009

Ok I've fixed it.