I have created dynamic add/remove fields in a frontend post submission page. Using $wpdb->insert, the system is working perfectly.
I have also created a draft edit page on the frontend. On this page I want these dynamic fields to get updated. I tried $wpdb->update but it only updates the last field. In short I want to update multiple rows on single click.
my code:
$project_id = $_SESSION['project_id'];
global $wpdb;
$reward_ids = $wpdb->get_results("SELECT * FROM wpxa_rewards WHERE project_id = $project_id");
foreach($reward_ids as $reward_id); $r_id = $reward_id->ID;
$count = count( $project_reward_title );
for ( $i = 0; $i < $count; $i++ ) {
global $wpdb;
$wpdb->update( 'wpxa_rewards',
array(
'reward_title' => "$project_reward_title[$i]",
'reward_description' => "$project_reward_description[$i]",
'reward_amount' => "$project_reward_amount[$i]",
'reward_shipping' => "$project_reward_shipping[$i]",
'est_date' => "$project_est_date[$i]"
),
array( 'ID' => $r_id ),
array(
'%s',
'%s',
'%d',
'%s',
'%s'
),
array( '%d' )
);
}
Plz help.. Thanks
"$project_reward_title[$i]", just write$project_reward_title[$i], it'll only confuse the interpreter.