form:
<input type="text" name="sample[]" id="sample1"/>
<input type="text" name="sample[]" id="sample2"/>
<input type="text" name="sample[]" id="sample3"/>
....
How to collect data from form, and then put each value to mysql?
I think you're looking for something like this to get you started:
$sample = is_array( $_POST['sample']) ? $_POST['sample'] : array();
if( count( $sample) > 0)
{
$sample = array_map( 'mysql_real_escape_string', $sample);
$sql = 'INSERT INTO table (something)
VALUES ( "' . implode( '" ), ( "', $sample) . ' ")';
}
$sample_array = $_POST['sample'];
foreach ($sample_array as $sample) {
//do what you want with it
}
A simple method is to do the following:
$sample = mysql_real_escape_string(stripslashes($_POST['sample']));
foreach($sample as $value) {
mysql_query("INSERT INTO table (foo) VALUE ($value)");
}
The syntax may be slightly off but that's the general jest of it.