php - Confused about storing data from this form -
i have been practising mysql , have came across issue can't solve. making large form able store information user in database. have managed make , store data simple form fields name, country, age, interest , etc using mysql , php.
i have table called users
in database have approximate 15 column different data name, country, age etc.
now have added field , confused how store data field.
here img of form ....
now if create column emp_name
how going store 1-4 values each user 5 fields each?
even if create different table ex - emp_history
how store data form each user?
your form should this:
<form name="xyz" method="post"> <table> <tr> <td>emp name</td><td>country</td><td>position</td> </tr> <tr> <td> <input type="text" name="data[emp_name][]" value="" /> <input type="text" name="data[country][]" value="" /> <input type="text" name="data[position][]" value="" /> </td> </tr> <tr> <td> <input type="text" name="data[emp_name][]" value="" /> <input type="text" name="data[country][]" value="" /> <input type="text" name="data[position][]" value="" /> </td> </tr> <tr> <td> <input type="text" name="data[emp_name][]" value="" /> <input type="text" name="data[country][]" value="" /> <input type="text" name="data[position][]" value="" /> </td> </tr> </table> when post form, value in php file this: $arr = $_post['data']; $cnt = count($arr['emp_name']); for($i=0; $i<$cnt; $i++) { $name = $arr['emp_name'][$i]; $country = $arr['country'][$i]; $position = $arr['position'][$i]; // insert sql $sql = insert emp_table(name, country, position) values('".$name."', '".$country."', '".$position."'); }
Comments
Post a Comment