I want to "get" more than one "item" - php

I want to send the "fill[]" and the "item[]" and my problem is the function write cant get the values of the variables, why?
What is wrong? Im new in this stuff.
<form action="/fill_sites/fill.php" method="get">
<input type="text" size="24" maxlength="20" name="fill[0]"/>
<input type="hidden" name="item[0]value="hella_apfelschorle"/>
<input type="text" size="24" maxlength="20" name="fill[1]"/>
<input type="hidden" name="item[1]" value="volvic_wasser"/>
..... so on
<input type="submit" value="Abschicken"/>
------------------------------------------------------------>[fill/php]>
$fill[0] = $_GET["fill[0]"];
$fill[1] = $_GET["fill[1]"];
$fill[2] = $_GET["fill[2]"];
$fill[3] = $_GET["fill[3]"];
$fill[4] = $_GET["fill[4]"];
$fill[5] = $_GET["fill[5]"];
$fill[6] = $_GET["fill[6]"];
$fill[7] = $_GET["fill[7]"];
$fill[8] = $_GET["fill[8]"];
$fill[9] = $_GET["fill[9]"];
$item[0] = $_GET["item[0]"];
$item[1] = $_GET["item[1]"];
$item[2] = $_GET["item[2]"];
$item[3] = $_GET["item[3]"];
$item[4] = $_GET["item[4]"];
$item[5] = $_GET["item[5]"];
$item[6] = $_GET["item[6]"];
$item[7] = $_GET["item[7]"];
$item[8] = $_GET["item[8]"];
$item[9] = $_GET["item[9]"];
write($counterFilename[$item[]], $fill);

you can do this by following code. it will get complete array.
$item = $_Get['item'];
$fill= $_Get['fill'];

use php's foreach statement to retrieve the content of fill and item
$fills = $_GET['fill'];
foreach($fills as $fill)
{
//do something with $fill
}
and the same for $item

Related

Adding Query HTML/PHPMYADMIN

Okay, so i really need help about the add query. I don't know what i did wrong. Please help. This is the code for my update.php
<form action="updateprocess.php" method="POST">
Description <input type="text" id="desc" name="desc">
SWL.Tonne <input type="text" id="swltonne" name="swltonne">
Inches <input type="text" id="inches" name="inches">
Model <input type="text" id="model" name="model">
SafetyFactor <input type="text" id="safetyfactor" name="safetyfactor">
Date/LPO <input type="text" id="datelpo" name="datelpo">
Manufacturer <input type="text" id="manu" name="manu">
Certificate.Number <input type="text" id="cnumber" name="cnumber">
Opening.Stock <input type="text" id="opstock" name="opstock">
January <input type="text" id="jan" name="jan">
February <input type="text" id="feb" name="feb">
March <input type="text" id="mar" name="mar">
April <input type="text" id="apr" name="apr">
May <input type="text" id="may" name="may">
June <input type="text" id="jun" name="jun">
July <input type="text" id="jul" name="jul">
August <input type="text" id="aug" name="aug">
September <input type="text" id="sep" name="sep">
October <input type="text" id="oct" name="oct">
November <input type="text" id="nov" name="nov">
December <input type="text" id="dec" name="dec">
Total.Used <input type="text" id="totuse" name="totuse">
Available.Balance <input type="text" id="avaibal" name="avaibal">
Minimumm.Stock <input type="text" id="minstocks" name="minstocks">
FOQ/FOI <input type="text" id="foqi" name="foqi">
Comment <input type="text" id="comm" name="comm">
</div>
<div class="submit-container"> <input class="submit-button"
type="submit" value="Add">
<input class="submit-button" type="submit" value="Clear" /></div>
</form>
and this is the updateprocess.php I really dont know what to do. My database name is franklinoffshore and i used mysqli
<?php
$desc = $_POST['desc'];
$swltonne = $_POST['swltonne'];
$inches = $_POST['inches'];
$model = $_POST['model'];
$safetyfactor = $_POST['safetyfactor'];
$datelpo = $_POST['datelpo'];
$manu = $_POST['manu'];
$cnumber = $_POST['cnumber'];
$opstock = $_POST['opstock'];
$jan = $_POST['jan'];
$feb = $_POST['feb'];
$mar = $_POST['mar'];
$apr = $_POST['apr'];
$may = $_POST['may'];
$jun = $_POST['jun'];
$jul = $_POST['jul'];
$aug = $_POST['aug'];
$sep = $_POST['sep'];
$oct = $_POST['oct'];
$nov = $_POST['nov'];
$dec = $_POST['dec'];
$totuse = $_POST['totuse'];
$avaibal = $_POST['avaibal'];
$minstocks = $_POST['minstocks'];
$foqi = $_POST['foqi'];
$comm = $_POST['comm'];
//connect to the serverand database
$franklinoffshore = mysqli_connect("localhost","root","","franklinoffshore");
//query the database
{
$result = mysqli_query($franklinoffshore, "INSERT INTO inventory_hooks(Description,SWLTonne,Inches,Model,SafetyFactor,DateLPO,Manufacturer,CertificateNumber,OpeningStocks,January,February,March,April,May,June,July,August,September,October,November,December,TotalUsed,AvailableBalance,MinimumStocks,FoqFoi,Comment)
VALUES('$description','$swltonne','$inches','$model','$safetyfactor','$datelpo','$manufacturer','$cnumber','$opstock','$jan','$feb','$mar','$apr','$may','$jun','$jul','$aug','$sep','$oct','$nov','$dec','$totuse','$avaibal','$minstocks','$foqi','$comm')");
}
?>
It keeps saying that Lines (too many lines) are Undefined Index. Or was i missing something?
PS: Its an inventory list thats why its toooo much.
Try this:
<?php
$franklinoffshore = mysqli_connect("localhost","root","","franklinoffshore");
$desc = mysqli_real_escape_string($franklinoffshore, $_POST['desc']);
$swltonne = mysqli_real_escape_string($franklinoffshore,$_POST['swltonne']);
$inches = mysqli_real_escape_string($franklinoffshore,$_POST['inches']);
$model = mysqli_real_escape_string($franklinoffshore,$_POST['model']);
$safetyfactor = mysqli_real_escape_string($franklinoffshore,$_POST['safetyfactor']);
$datelpo = mysqli_real_escape_string($franklinoffshore,$_POST['datelpo']);
$manu = mysqli_real_escape_string($franklinoffshore,$_POST['manu']);
$cnumber = mysqli_real_escape_string($franklinoffshore,$_POST['cnumber']);
$opstock = mysqli_real_escape_string($franklinoffshore,$_POST['opstock']);
$jan = mysqli_real_escape_string($franklinoffshore,$_POST['jan']);
$feb = mysqli_real_escape_string($franklinoffshore,$_POST['feb']);
$mar = mysqli_real_escape_string($franklinoffshore,$_POST['mar']);
$apr = mysqli_real_escape_string($franklinoffshore,$_POST['apr']);
$may = mysqli_real_escape_string($franklinoffshore,$_POST['may']);
$jun = mysqli_real_escape_string($franklinoffshore,$_POST['jun']);
$jul = mysqli_real_escape_string($franklinoffshore,$_POST['jul']);
$aug = mysqli_real_escape_string($franklinoffshore,$_POST['aug']);
$sep = mysqli_real_escape_string($franklinoffshore,$_POST['sep']);
$oct = mysqli_real_escape_string($franklinoffshore,$_POST['oct']);
$nov = mysqli_real_escape_string($franklinoffshore,$_POST['nov']);
$dec = mysqli_real_escape_string($franklinoffshore,$_POST['dec']);
$totuse = mysqli_real_escape_string($franklinoffshore,$_POST['totuse']);
$avaibal = mysqli_real_escape_string($franklinoffshore,$_POST['avaibal']);
$minstocks = mysqli_real_escape_string($franklinoffshore,$_POST['minstocks']);
$foqi = mysqli_real_escape_string($franklinoffshore,$_POST['foqi']);
$comm = mysqli_real_escape_string($franklinoffshore,$_POST['comm']);
//connect to the serverand database
$result = mysqli_query($franklinoffshore,
"INSERT INTO inventory_hooks
(Description,SWLTonne,Inches,Model,
SafetyFactor,DateLPO,Manufacturer,
CertificateNumber,OpeningStocks,
January,February,March,April,May,
June,July,August,September,October,
November,December,TotalUsed,AvailableBalance,
MinimumStocks,FoqFoi,Comment) VALUES
('$description','$swltonne',
'$inches','$model','$safetyfactor',
'$datelpo','$manufacturer','$cnumber',
'$opstock','$jan','$feb','$mar','$apr',
'$may','$jun','$jul','$aug','$sep','$oct',
'$nov','$dec','$totuse','$avaibal','$minstocks',
'$foqi','$comm')");
if($result) {
echo "It works";
}
?>

Group Arrays By Another Array?

I'm trying to sort one array by another array. Both these arrays get their content from a form.
Here's my form code:
<form method="post" action="">
<div class="groupcontainer">
<br/><label>Group One:</label><br/>
<input type="text" name="groupname[]" value="groupone" /><br/>
<br/><label>Variable Group One:</label><br/>
<input type="text" name="variable[]" value="variableone" />
<input type="text" name="variable[]" value="variabletwo" />
</div>
<br/>
<div class="groupcontainer">
<br/><label>Group Two:</label><br/>
<input type="text" name="groupname[]" value="grouptwo" /><br/>
<br/><label>Variable Group Two:</label><br/>
<input type="text" name="variable[]" value="variablethree" />
<input type="text" name="variable[]" value="variablefour" />
</div>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
Here's the PHP code:
<?php
if (!$_POST['submit'] == "") {
foreach($_POST['groupname'] as $groupname) {
$groupnum = 1;
foreach($_POST['variable'] as $variable) {
print "$".$groupname.$groupnum." = '".$variable."';<br/>";
$groupnum++;
}
print "$".$groupname." = array(";
for ($arrnum = 1; $arrnum <= count($_POST['variable']); $arrnum++) {
print "$".$groupname.$arrnum.", ";
}
print ");<br/><br/>";
}
}
?>
This is the result I get when I submit the form:
$groupone1 = '$variableone';
$groupone2 = '$variabletwo';
$groupone3 = '$variablethree';
$groupone4 = '$variablefour';
$groupone = array($groupone1, $groupone2, $groupone3, $groupone4, )
$grouptwo1 = '$variableone';
$grouptwo2 = '$variabletwo';
$grouptwo3 = '$variablethree';
$grouptwo4 = '$variablefour';
$grouptwo = array($grouptwo1, $grouptwo2, $grouptwo3, $grouptwo4, )
This is the result that I actually want:
$groupone1 = '$variableone';
$groupone2 = '$variabletwo';
$groupone = array($groupone1, $groupone2)
$grouptwo1 = '$variablethree';
$grouptwo2 = '$variablefour';
$grouptwo = array($grouptwo1, $grouptwo2)
The whole thing needs to be dynamic since I want to add as many groups and variables as I want.
I've been searching for an answer for days and already asked two people who didn't know an answer. Maybe you guys can help. Thanks!
Update:
Just to clarify a few points:
So basically I want to be able to add as many input forms as I want (I use jQuery for that) to create as many groups and variables as I want, for example like this:
$groupwuteva1 = 'hello';
$groupwuteva2 = 'bye':
$randomname1 = 'green';
$randomname2 = 'blue';
$randomname3 = 'red';
$blabla1 = 'abc';
$blabla2 = 'xyz';
$blabla3 = '123';
$blabla4 = 'bla';
Whatever I use as groupname will be used in array one, e.g. I call a group "Colors" and the variables I put into the form for that group are "blue", "red" and "green". Then I would get this code:
$colors1 = 'green';
$colors2 = 'blue';
$colors3 = 'red';
I hope this clairfies some questions. And thanks a ton for all responses so far!
You can take the group name as a container to store all associated variable values in it. And later, use variable variables and implode() function to process your html form.
HTML
<form method="post" action="">
<div class="groupcontainer">
<br/><label>Groupe One:</label><br/>
<input type="text" name="groupname[]" value="groupone" /><br/>
<br/><label>Variable Group One:</label><br/>
<input type="text" name="groupone[]" value="variableone" />
<input type="text" name="groupone[]" value="variabletwo" />
</div>
<br/>
<div class="groupcontainer">
<br/><label>Groupe Two:</label><br/>
<input type="text" name="groupname[]" value="grouptwo" /><br/>
<br/><label>Variable Group One:</label><br/>
<input type="text" name="grouptwo[]" value="variablethree" />
<input type="text" name="grouptwo[]" value="variablefour" />
</div>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
PHP
if(isset($_POST['submit'])){
foreach($_POST['groupname'] as $value){
$arr = array();
$i = 1;
foreach($_POST[$value] as $v){
$var = $value . $i;
$$var = $v;
echo $var . " = " . $$var . "<br />";
$arr[] = $$var;
++$i;
}
$output = $value . " = array(" . implode(",", $arr) . ")";
echo $output . "<br /><br />";
}
}
Output:
groupone1 = variableone
groupone2 = variabletwo
groupone = array(variableone,variabletwo)
grouptwo1 = variablethree
grouptwo2 = variablefour
grouptwo = array(variablethree,variablefour)
try this form:
<form method="post" action="">
<?php foreach(array('groupone', 'grouptwo') as $num):?>
<div class="groupcontainer">
<br/><label>Groupe <?php echo $num;?>:</label><br/>
<input type="text" name="groupname[]" value="<?php echo $num;?>" /><br/>
<br/><label>Variable Group <?php echo $num;?>:</label><br/>
<input type="text" name="variable[<?php echo $num;?>][]" value="<?php echo uniqid();?>" />
<input type="text" name="variable[<?php echo $num;?>][]" value="<?php echo uniqid();?>" />
</div>
<br/>
<?php endforeach;?>
<input type="submit" name="submit" value="Submit" />
</form>
and code:
if ($_POST) {
foreach($_POST['groupname'] as $groupname) {
$$groupname = array();
foreach($_POST['variable'][$groupname] as $variable) {
${$groupname}[] = $variable;
}
}
var_dump($groupone);
var_dump($grouptwo);
}

php: how to shorten many $_POST[];

I'm working on a page with many insert fields.
how can i shorten the following code?
$title_1 = $_POST['title_1'];
$content_1 = $_POST['content_1'];
$link_1 = $_POST['link_1'];
$img_link_1 = $_POST['img_link_1'];
$title_2 = $_POST['title_2'];
$content_2 = $_POST['content_2'];
$link_2 = $_POST['link_2'];
$img_link_2 = $_POST['img_link_2'];
$title_3 = $_POST['title_3'];
$content_3 = $_POST['content_3'];
$link_3 = $_POST['link_3'];
$img_link_3 = $_POST['img_link_3'];
You could loop through the $_POST array like this:
foreach ($_POST as $key => $value) {
${$key} = $value;
}
This will make your post variable like $_POST['title_1'] into $title_1
Remember your post names will have to be the exact names you want your variables to be referenced by.
I would do:
$howmany = 3; // How many sets of fields are submitted.
for($i=0;$i<$howmany;$i++){
$field[$i]['title'] = $_POST['title_'.$i];
$field[$i]['content'] = $_POST['content_'.$i];
$field[$i]['link'] = $_POST['link_'.$i];
$field[$i]['img_link'] = $_POST['img_link_'.$i];
}
Then you can access data in $field[1]['title'] form.
You can use extract (http://php.net/manual/en/function.extract.php): extract($_POST)
But you should be careful -- what if the client POSTs user_id, or something? At the least, you should specify that $_POST values won't overwrite already-defined variables: extract($_POST, EXTR_SKIP)
I redid this answer after you edited your post. Use variable variables.
foreach ($_POST as $key => $val)
{
if (preg_match('/^(([a-z]+_)+\d)$/', $key, $match)
{
$$match[0] = $val;
}
}
Use [a-z0-9] or [a-zA-Z0-9] as alternatives.
<?php
$key_prefixes = array (
'title',
'content',
'link',
'img_link'
);
$i = 1;
while (true) {
$post_values_missing = 0;
foreach ($key_prefixes as $key_prefix) {
$key = $key_prefix . '_' . $i;
if (!isset($_POST[$key])) {
$post_values_missing += 1;
continue;
};
$val = $_POST[$key];
// do something with $val
}
// did you get any values through this iteration?
$post_values_exist_bool = (count($key_prefixes) !== $post_values_missing);
// if not, you must've gotten them all
if (false === $post_values_exist_bool) {
break;
}
$i += 1;
}
The cleanest way to do this would be to use PHP's POST data processing capabilities to do the work for you.
Consider using your HTML form names as follows:
<form action="{url}" method="post">
<input type="text" name="data[0][title]" />
<input type="text" name="data[0][content]" />
<input type="text" name="data[0][link]" />
<input type="text" name="data[0][image_link]" />
<input type="text" name="data[1][title]" />
<input type="text" name="data[1][content]" />
<input type="text" name="data[1][link]" />
<input type="text" name="data[1][image_link]" />
...
</form>
In PHP extract the data as follows:
$data = $_POST['data'];
This shortens your PHP code to just one line. This statement will directly give you an array in PHP of the data form input. A var_dump will look as follows:
array (
0 => array('title'=>'...','content'=>'...','link'=>'...','image_link'=>'...'),
1 => array('title'=>'...','content'=>'...','link'=>'...','image_link'=>'...'),
...
)
You don't have to change your name, just make it array;
<input type="text" name="title[]" />
<input type="text" name="content[]" />
<input type="text" name="link[]" />
<input type="text" name="image_link[]" />
<input type="text" name="title[]" />
<input type="text" name="content[]" />
<input type="text" name="link[]" />
<input type="text" name="image_link[]" />
<input type="text" name="title[]" />
<input type="text" name="content[]" />
<input type="text" name="link[]" />
<input type="text" name="image_link[]" />
PHP:
extract($_POST);
$count=count($title);
for($i=0;$i<$count;$i++) {
//You can perform your any function on this loop, to get title use $title[$i]
}

How to get same fields in POST

<form action="form.php" id="form">
<input type="text" name="name_1"><input type="text" name="city_1"><input type="text" name="country_1">
<input type="text" name="name_2"><input type="text" name="city_2"><input type="text" name="country_2">
<input type="text" name="name_3"><input type="text" name="city_3"><input type="text" name="country_3">
<input type="submit">
</form>
How is the best method for get this data in form.php file? This is generated with jQuery. Can be 3 (as now) or 30.
In form.php i have:
$data = new Data();
$data->name = $_POST['name_1'];
$data->city = $_POST['city_1'];
$data->country = $_POST['country_1'];
$data->save();
$data = new Data();
$data->name = $_POST['name_2'];
$data->city = $_POST['city_2'];
$data->country = $_POST['country_2'];
$data->save();
$data = new Data();
$data->name = $_POST['name_3'];
$data->city = $_POST['city_3'];
$data->country = $_POST['country_3'];
$data->save();
But if there is over 3? I would like use foreach, but how? How can i generated input or get this data?
Use name[], city[] and country[] as your input names. Then they'll come through to PHP as arrays which you can iterate with foreach.
If you can change the names of the input elements you could do it like that:
<input type="text" name="items[1][name]"><input type="text" name="items[1][city]"><input type="text" name="items[1][country]">
<input type="text" name="items[2][name]"><input type="text" name="items[2][city]"><input type="text" name="items[2][country]">
<input type="text" name="items[3][name]"><input type="text" name="items[3][city]"><input type="text" name="items[3][country]">
The numbers don't have to be adjacent but the have to be unique. To convert the $_POST-data to your data-model would then look like that:
$items = $_POST['items'];
$dataList = array();
foreach($items as $item) {
$data = new Data();
$data->name = $item['name'];
$data->city = $item['city'];
$data->country = $item['country'];
$dataList[] = $data;
}
Of course you can add as many items as you want.
If you can't change the names of the input elements then you could use one of the other solutions. I would only modify them so that the number of elements is not hard coded like:
$dataList = array()
for($i = 1; isset($_POST["name_$i"]); ++$i) {
$data = new Data();
$data->name = $_POST["name_$i"];
// ... and so on
$dataList[] = $data;
}
Of course, with that solution the numbers must be continuous/adjacent.
You can use your for each with on time built strings like 'name_.$i', with $i as a counter
You can use a for loop:
for ($i = 1; $i <= 3; $i++) {
$data = new Data();
$data->name = $_POST['name_'.$i];
$data->city = $_POST['city_'.$i];
$data->country = $_POST['country_'.$i];
$data->save();
}
But if you could change your html like:
<input type="text" name="name[]"><input type="text" name="city[]"><input type="text" name="country[]">
<input type="text" name="name[]"><input type="text" name="city[]"><input type="text" name="country[]">
<input type="text" name="name[]"><input type="text" name="city[]"><input type="text" name="country[]">
You will not need to know the count.(name_1,name_2 would be better to be the id but not name)
foreach ($_POST['name'] as $index => $name) {
$data = new Data();
$data->name = $name;
$data->city = $_POST['city'][$index];
$data->country = $_POST['country'][$index];
$data->save();
}

php add multiple input fields to mysql

I have this code:
<html>
<body>
<form id="myForm" method="post" action="add-data.php">
<input type="submit">
<input type="text" name="pollquestion">
<input type="text" name="polloption1">
<input type="text" name="polloption2">
</form>
Add option
<script>
var optionNumber = 3;
function addOption() {
var theForm = document.getElementById("myForm");
var newOption = document.createElement("input");
newOption.name = "polloption"+optionNumber+""; // poll[optionX]
newOption.type = "text";
theForm.appendChild(newOption);
optionNumber++;
}
</script>
</body>
</html>
If i add more inputs i will have something like this:
<input name="pollquestion" type="text">
<input name="polloption1" type="text">
<input name="polloption2" type="text">
<input name="polloption3" type="text">
<input name="polloption4" type="text">
<input name="polloption5" type="text">
<input name="polloption6" type="text">
The php code is something like this:
$qu = $_POST['pollquestion'];
$op1 = $_POST['polloption1'];
$op2 = $_POST['polloption2'];
$query = "INSERT into `".$db_table."` (question, option1, option2) VALUES ('" . $qu . "','" . $op1 . "','" . $op2 . "')";
How can i add this data to mysql for every added row? Thanks!
One way of many...
$query = "INSERT into `$db_table` SET `question` = '".mysql_real_escape_string($_POST['pollquestion'])."'";
foreach (range(1,6) as $idx) {
if (!empty($_POST['polloption'.$idx])) {
$query .= ", `option$idx` = '".mysql_real_escape_string($_POST['polloption'.$idx])."'";
}
}
of course the mysql_real_escape_string is important to avoid http://en.wikipedia.org/wiki/SQL_injection
First, you need to know how many options you're submitting so add another constant input to the form:
<input type="hidden" id="numOptions" name="numOptions"/>
In the addOption() function update its value (before incrementing optionNumber):
document.getElementById( "numOptions" ).value = optionNumber;
On the server side you need to create your query dynamically like so:
$options = array();
$values = array();
$numOptions = intval( $_POST[ "numOptions" ] );
for ( $i = 1; $i <= $numOptions; $i++ )
{
$options[] = "option$i";
$values [] = "'" . mysql_real_escape_string( $_POST[ "polloption$i" ] ) . "'";
}
$query = "INSERT INTO $db_table(" . implode( ',', $options ) . ") VALUES( '" .
implode( ',', $values );
Please mind the escaping of the received strings! very important to prevent SQL injections.
HTML
<input name="title" type="text">
<input name="descr" type="text">
<input name="question[1]" type="text">
<input name="option[1][1]" type="text">
<input name="option[1][2]" type="text">
<input name="option[1][3]" type="text">
<input name="right[1]" type="radio" value=1>
<input name="right[1]" type="radio" value=2>
<input name="right[1]" type="radio" value=3>
<input name="question[2]" type="text">
<input name="option[2][1]" type="text">
<input name="option[2][2]" type="text">
<input name="option[2][3]" type="text">
<input name="right[2]" type="radio" value=1>
<input name="right[2]" type="radio" value=2>
<input name="right[2]" type="radio" value=3>
PHP
$title = mysql_real_escape_string($_POST['title'])
$descr = mysql_real_escape_string($_POST['descr'])
$query = "INSERT into `polls` (title,descr) VALUES ('$title', '$descr')";
$id = $db->query($query);
foreach ($_POST['question'] as $num => $q) {
$q = mysql_real_escape_string($q)
$query = "INSERT into `poll questions` (poll,question) VALUES ($id,'$q')";
$db->query($query);
foreach ($_POST['option'][$num] as $i => $opt) {
$right = ($_POST['right'][$num]) == $i)?1:0;
$opt = mysql_real_escape_string($opt)
$num = intval($num);
$query = "INSERT into `poll options` (poll,num,option,right)
VALUES ($id,$num,'$opt',$right)";
}
}
You can iterate $_POST, matching keys with regular patterns, something like that:
foreach($_POST as $key => $value) {
preg_match('/(\w+)(\d+)/Uis', $key, $m);
if($m[1] == 'polloption') {
// concatenate new values to your query
}
}
Remembering relational databases, you have fixed number of attributes in your table. So you should add fixed number of options.

Categories