I have searched the site, but can not find the answer or how it would relate to how I have my query set up. Here is my file that processing my post data and passes to db. I have form that is wrapped around a table. The cells in the table are populated by an array. When I leave this page I want the values in the table cells written to a new table in the db. Each row in the table represents a separate row in the db.
Here is my form where all my post data is coming from.
<form action="post_movement.php?class_id=<?php echo $class_id; ?>&pagenum=<?php echo $pagenum; ?>" method="post">
<table border=1 width=800px>
<tr>
<th width=300px>Client</th>
<th width=50px>Order</th>
<th width=200px>Movements</th>
<th>Sets/Reps/Seconds</th>
<th width=150px>Rest</th>
<th>X Completed</th>
</tr>
<?php
// Get workout class and output in table format -------------------------------------------------
if(empty($workout_class) === false)
{
foreach($workout_class as $wc){
if ($wc['pagenum'] !== $pagenum) continue 1;
echo '<tr>
<td><input type="hidden" name="first_name[]" value="'.($wc['first_name']).'">'. ($wc['first_name']).'
<span><input type="hidden" name="nickname[]" value="'.($wc['nickname']).'">('. ($wc['nickname']).')</span>
<span><input type="hidden" name="last_name[]" value="'.($wc['last_name']).'">'. ($wc['last_name']).'</span>
</td>
<td><input type="hidden" name="order[]" value="'.($wc['order']).'">'. ($wc['order']). '</td>
<td>
<select name="movement[]" width=200>
<option>'. ($wc['mv_00']). '</option>
<option>'. ($wc['mv_01']). '</option>
<option>'. ($wc['mv_02']). '</option>
<option>'. ($wc['mv_03']). '</option>
<option>'. ($wc['mv_04']). '</option>
</select></td>
<td><input type="hidden" name="rep_set_sec[]" value="'.($wc['rep_set_sec']).'">'. ($wc['rep_set_sec']). '</td>
<td><input type="hidden" name="rest[]" value="'.($wc['rest']).'">'. ($wc['rest']). '</td>
<td>00</td>
</tr>';
} // foreach($data_array
//print_r($data_array);
} // if(!empty
?>
<! End Table ---------------------------------------------------------------------------------->
</table>
<input type="submit" value="Complete Movement">
</form>
Here is my php that process the post data from the form and submits it to the query.
if (empty($_POST)=== false){
$movement_data = array('user_id', 'class_id', 'class_name', 'first_name', 'last_name', 'nickname', 'order', 'movement', 'rep_set_sec', 'rest', 'date');
foreach($movement_data as $key => $value){
$movement_data = array(
'user_id' => $session_user_id,
'class_id' => $_GET['class_id'],
'class_name' => $class_name,
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'nickname' => $_POST['nickname'],
'order' => $_POST['order'],
'movement' => $_POST['movement'],
'rep_set_sec' => $_POST['rep_set_sec'],
'rest' => $_POST['rest'],
'date' => $today
);
}
completed_movement($movement_data);
//header('Location: new_client.php');
//exit ();
}
Here is my query that inserts the POST data into db.
function completed_movement($movement_data){
array_walk($movement_data, 'array_sanitize');
$fields = '`' . implode('`, `', array_keys($movement_data)) . '`';
$data = '\'' . implode('\', \'', $movement_data) . '\'';
$query = mysql_query ("INSERT INTO `completed_movements` ($fields) VALUES ($data)");
}
HTML form page has two table rows of data and looks like this.
Colby (Big Cheese) Dodson | 1A | Key Movement | Sets/Reps/Seconds | Rest|
-------------------------------------------------------------------------
Mike (Big Mac) Mckenzie | 1A | Key Movement | Sets/Reps/Seconds | Rest|
A var_dump ($_POST) produces this. I can see that value in there just not sure if it looks like its supposed to.
array(7) {
["first_name"]=> array(2) {
[0]=> string(5) "Colby"
[1]=> string(4) "Mike" }
["nickname"]=> array(2) {
[0]=> string(10) "Big Cheese"
[1]=> string(7) "Big Mac" }
["last_name"]=> array(2) {
[0]=> string(6) "Dodson"
[1]=> string(8) "McKenzie" }
["order"]=> array(2) {
[0]=> string(2) "1A"
[1]=> string(2) "1A" }
["movement"]=> array(2) {
[0]=> string(12) "Key Movement"
[1]=> string(12) "Key Movement" }
["rep_set_sec"]=> array(2) {
[0]=> string(17) "Sets/Reps/Seconds"
[1]=> string(17) "Sets/Reps/Seconds" }
["rest"]=> array(2) {
[0]=> string(4) "Rest"
[1]=> string(4) "Rest" }
}
Is this what its supposed to look like when it does the var_dump?
I need each row of my array to look like this. The first three values are the user_id, class_id, & class_name and are not part of my html form on the previous page. These vales are picked up on the parsing script page and passed along with each row of my results.
$row = array(29, 48, Class 1, Colby, Big Cheese, Dodson, 1A, Key Movement, Sets/Reps/Secons, Rest)
I need a row like this for each entry from my form.