Jump to content

$_POST array


web_master

Recommended Posts

hi, me with a new problem

 

in form Ive got:

 

query....

 

while... {

 

<input type="checkbox" name="tt_reg_int_check[<?php print $request['tt_product_group_id'];?>]" value="1">

 

}

 

(tt_product_group_id will increase by inserting data)

 

 

in post file what can I do to:

 

1. array posted tt_reg_int_check[<?php print $request['tt_product_group_id'];?>]

2. if not exist create column in table tt_product named tt_reg_int_check_[nr of tt_product_group_id]

3. insert posted value "1" in column tt_reg_int_check_[nr of tt_product_group_id]

 

uh, I hope its understandable...

Link to comment
https://forums.phpfreaks.com/topic/53832-_post-array/
Share on other sites

<?php
while(...)
{
?>
<input type="checkbox" name="tt_reg_int_check[]" value="<?php print $request['tt_product_group_id'];?>">
<?php
}
?>

 

processing code

 

<?php

$qry = "SHOW COLUMNS FROM `tt_product`"
$qry = mysql_query($qry);
while($row = mysql_fetch_assoc($qry))
{
$fields[] = $row['Field'];
}

$alter = NULL;
foreach($_POST['tt_reg_int_check'] as $key => $val)
{
if (!array_keys($fields,$val))
{

  $alter .= "ADD `tt_reg_int_check_[" . $val . "]` SMALLINT(3) DEFAULT '1' NOT NULL ,"
}
}

if (!is_null($alter))
{
$alter = substr($alter,0, strlen($alter) - 1);
$qry = "ALTER TABLE" . $alter;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/53832-_post-array/#findComment-266130
Share on other sites

Toon - I miss something... :(

 

1)

this is a first file:

 

 

<form name="registration_form" action="registration_post.php" method="post">

//Query_return product groups

$query_return = mysql_query("SELECT * FROM tt_product_group ORDER BY tt_product_group_id DESC");

 

if(!$query_return) {

echo mysql_error();

exit;

}

 

while ($request = mysql_fetch_array($query_return)) {

?>

<tr>

<td>

<input type="checkbox" name="tt_reg_int_check[<?php print $request['tt_product_group_id'];?>]" value="1">

</td>

</tr>

<?php }?>

</form>

 

 

 

2)

this is the table structure:

 

CREATE TABLE `tt_reg` (

  `tt_reg_id` int(5) unsigned NOT NULL auto_increment,

  `tt_reg_name` varchar(255) default NULL,

  `tt_reg_fname` varchar(255) default NULL,

  `tt_reg_email` varchar(255) default NULL,

  `tt_reg_city` varchar(255) default NULL,

  `tt_reg_phone` varchar(30) default NULL,

  `tt_reg_datum` datetime NOT NULL default '0000-00-00 00:00:00',

  `tt_reg_ip` varchar(80) NOT NULL default '',

  `tt_reg_password` varchar(30) NOT NULL default '',

  PRIMARY KEY  (`tt_reg_id`),

  UNIQUE KEY `tt_reg_id` (`tt_reg_id`),

  KEY `tt_reg_id_2` (`tt_reg_id`)

) TYPE=MyISAM;

 

3)

than is here the registration_post.php file:

 

so here I want to add the tt_reg_int_check[X] fileds in `tt_reg` table posted from firs file. If is that what You posted, than its OK - just must to think about it...

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/53832-_post-array/#findComment-266144
Share on other sites

err - what I posted will do what you asked in the OP (with the proper form tags and submits buttons etc.).  I am a little confused at why you need to add fields to your database - I suspect what you want to do is add a new record but you will have to assess your table structure and see how you can maintain a set number of fields and simply differetiate on field value.

Link to comment
https://forums.phpfreaks.com/topic/53832-_post-array/#findComment-266201
Share on other sites

I dont know, maybe I think different ...

 

Ive got a table where are the products. Every product have own ID. The ID of prduct will increas when added another product to a row. This product will upload the administrator.

 

then when somebody register must to see all the products (product ID's) and have a possibility to choose (check) his interrest (tt_reg_int_check[X]) - not only one but all products. That mean that if yesterday have 5 product I wil have:

tt_reg_int_check[1]

tt_reg_int_check[2]

tt_reg_int_check[3]

tt_reg_int_check[4]

tt_reg_int_check[5]

 

but the tomorrow I will have a 6,7,8...

and the customer, who will register today can choose all 'tt_reg_int_check's.

 

How can I insert in field all that [nr]'s?

Link to comment
https://forums.phpfreaks.com/topic/53832-_post-array/#findComment-266268
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.