This topic is locked
[SOLVED]

 inserting detail data after creating new master

2/13/2011 8:40:17 AM
PHPRunner General questions
D
duck author

I created this event on master add page:-
function AfterAdd($values,$keys,$inline)

{
//get last insert record id

$last_id = mysql_insert_id(); // for checking only

print_r ($last_id); // for checking only
//** Save new data in another table ****

global $conn,$user_exercise;

$strSQLInsert = "INSERT INTO user_exersise (User_id, User_Workout_id, exersize_id) values (";

$strSQLInsert .= $values[$_SESSION['OwnerID']].",";

$strSQLInsert .= $values[mysql_insert_id()];

$strSQLInsert .= $values["1"];

$strSQLInsert .= ")";

db_exec($strSQLInsert,$conn);
this results in error:-
8

Error description Undefined offset: 71

URL localhost/members/op1/user_workout_add.php?

Error file C:\xampp\htdocs\members\op1\include\user_workout_events.php

Error line 38

SQL query insert into user_workout (user_workout.Workout_id, user_workout.Workout_Date, user_workout.Workout_Time_Length, user_workout.User_id) values (2, '2011-02-17', 5, 1)
which is the master table add function

71 is correct value of mysql_insert_id()

any suggestion appreciated

D
duck author 2/13/2011

$last_id = mysql_insert_id();

$lastuser_id = $_SESSION["OwnerID"];

global $conn;

$strSQL = "SELECT execise.id AS exercise_id FROM workout";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs)){
$lastexercise = $data["exercise_id"];
//** Insert records into exercise table ****
$strSQLInsert = "Insert into user_exercise (Exercise_id,User_Workout_id,User_id) values ($lastexercise,$last_id,$lastuser_id)";
db_exec($strSQLInsert,$conn);

}
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=56448&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

answered it myself

hope it helps others not have the angst