I'm trying to save a html table rows into php array and then save the array in database.
<form action="" method="post">
<table class="widefat" id="theTable">
<thead>
<tr>
<th>Level Identifier</th>
<th>Non-logged in message</th>
<th>Logged in message</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
<td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
<td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
</tr>
<tr>
<td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
<td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
<td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
</tr>
</tbody>
</table>
</form>
How can i retrieve each row data and save it to array element and finally I would be saving the array to db? Thanks
This is basic PHP usage. You give your inputs names, an when you submit your form, your script in the submitted page will do the job.
Your values will reside in the
array. So you access them by
you will have to go through each value by calling its name and then put it in the database accordingly.
IF YOU WANT TO SAVE HTML OF EACH ROW DO:
Use JQuery.
then use ajax to post this data
In PHP side you do:
you cant save php array into database therefore you need to serialize it and when you retrieve it from DB use unserialize()
IF you meant that you wanted to save the input and text area values then you need to set the names for each of the element and then access them in your script using $_POST.
NOTE/HINT: FYI do not use html table to lay out the form elements. Tables should be used for data representation. You could easily do samething using divs and css