Well, there's an easy way I can think of.
For the name attribute of your textfields, make them in an array like this.
Assuming this is how you generate your number of steps and such.
<?php
// Get POST steps
$steps = (int)$_POST['steps'];
// Return string
$return = '';
// Loop number of steps needed and adds textareas
for($i = 0; $i < $steps; $i++){
$step_num = $i+1;
$return .= '<textarea name="stepcontent['.$step_num.']" id="stepcontent'.$step_num.'" rows="10" cols="10"></textarea>';
}
echo $return;
?>
That will echo out as many textareas as you need, and how ever you're doing it. Just be sure the name has the '[]' to indicate an array, and you can even make an associative array with it to make it easier, since I doubt your step numbering will start with 0 as in the array.
This way, you can then do this to combine your steps easily when the data is posted back.
<?php
// Safety precautions for posted data
// Strip HTML Function
function strip_html($data){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip Javascript
'@<style[^>]*?>.*?</style>@siU', // Strip Style Tags
'@<[\/\!]*?[^<>]*?>@si', // Strip HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip Multi-line Comments (CDATA)
);
return preg_replace($search, '', $data);
}
// Clean User Data Function
function cleandata($data){
return trim(htmlspecialchars(strip_html($data)));
}
// Posted data
$steps_content = $_POST['stepcontent'];
// Complete content string
$full_content = '';
// Loop and add each step into the string, and clean it up
foreach($step_content as $step => $content)
$full_content .= cleandata($content);
# And your query goes here, just use $full_content to insert the tutorial data
?>