billgod Posted January 18, 2011 Share Posted January 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224794-variable-amount-of-variables/ Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/224794-variable-amount-of-variables/#findComment-1161151 Share on other sites More sharing options...
billgod Posted January 18, 2011 Author Share Posted January 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224794-variable-amount-of-variables/#findComment-1161158 Share on other sites More sharing options...
crabfinger Posted January 18, 2011 Share Posted January 18, 2011 consider arrays, they work with html too <input type="text" name="mypost[22]" value="" /><input type="text" name="mypost[54]" value="" /> Quote Link to comment https://forums.phpfreaks.com/topic/224794-variable-amount-of-variables/#findComment-1161196 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.