Jump to content

Recommended Posts

If I knew what to call it I could have searched it.  So I will just explain.

 

I have a form that is pulling from a database to build the following.

echo <input name='$row[id]' type='text' id='$row[id]' size=2>;

 

This will build a page that has this

<input name='22' type='text' id='22' size=2>

<input name='54' type='text' id='54' size=2>

 

This part works great.  The problem is when I try to add it to the database.  How can I insert variables that I don't know the names of?  They will be something like $_POST[22]  $_POST[54] and so on.  I hope someone can understand my jibberish.

 

I am sure there is a WAY better way to do this.

Link to comment
https://forums.phpfreaks.com/topic/224794-variable-amount-of-variables/
Share on other sites

There are a few ways to do this.

 

1) You can store the values and pass them as a hidden field to the processing page.

2) (This is a bit unsafe) You can dynamically go through your post values:

foreach($_POST as $key =>$value)
{
   echo "post: $key => $value";
}

Here is my query I currently have

		$sql2="insert into tbl_orders (col_orderid, col_prodid, col_qty) values ( '$orderid', '$row[id]', $_POST[number])";
	$result2=mysql_query($sql2) or die ('Error: '.mysql_error ());

 

I need to be able to insert $_POST[22], $_POST[54] and so on.  I am not sure how your suggestion is going to accomplish this.  I need $_POST[number] to change with every loop.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.