Add info to row of table Data
-
I have a table wp_lb_family_group which has the following columns id, person_id, sibling_id, father_id, mother_id, family_id
Currently when a new family is created the person_id and family_id are automatically entered into the table successfully.
However at a later stage when a new family member is created I wish to enter their person_id as a sibling, father or mother in the sibling_id, father_id, mother_id columns of this table.
This is where I have hit a brick wall
(I am only trying to place the father_id at this stage. I have not added any code to determine whether the person is the mother, father or sibling. I will do this once I know how to put the info into the table)
The code I have at this stage is:
<?php require_once('../../../wp-config.php'); // Get values from form $person=$_POST['person']; $family_type=$_POST['family_type']; $id=$_POST['id']; $first_name=$_POST['first_name']; $family_name=$_POST['family_name']; $date_of_birth=$_POST['date_of_birth']; $date_of_death=$_POST['date_of_death']; ?> <!--I am only echoing the following variables to ensure they have been passed succesfuly. This will be removed at a later date--> <?php echo $person;?> <br /> <?php echo $family_type;?> <br /> <?php echo $id;?> <br /> <?php echo $first_name;?> <br /> <?php echo $family_name;?> <br /> <?php echo $date_of_birth;?> <br /> <?php echo $date_of_death;?> <?php global $wpdb; $table_name = $wpdb->prefix . "lb_person"; $wpdb->insert($table_name,array('first_name'=>$_POST['first_name'], 'family_name'=>$_POST['family_name'], 'date_of_birth'=>$_POST['date_of_birth'], 'date_of_death'=>$_POST['date_of_death'])); $strSql = 'select last_insert_id() as lastId'; $result = mysql_query($strSql); while($row = @mysql_fetch_assoc($result)){ $lastid = $row['lastId']; } $family_id = $wpdb->get_var( "SELECT family_id FROM wp_lb_family_group" ); <!--I am only echoing the following variables to ensure they have been passed succesffuly. This will be removed at a later date--> echo "<p>Family ID{$family_id }</p>"; $table_name = $wpdb->prefix . "lb_family_group"; $wpdb->insert($table_name,array('person_id'=>$lastid, 'family_id'=>$family_id));
Up to here everything works successfully.
The information is added to the lb_person table and the person_id and family_id are added to the lb_family_group table.
It is when I try to add the new family member to the father_id column that I am having problems.
I have tried the code with no effect:
$wpdb->update( $table_name, array( 'father_id' => $lastid), array( 'person_id' => $id), array( '%d'), array( '%d' )); ?>
Any assistance would be appreciated.
- The topic ‘Add info to row of table Data’ is closed to new replies.