papaface Posted December 15, 2006 Share Posted December 15, 2006 Hello,Could someone please inform me of how I would select a specific key in this loop?[code]foreach ($_POST as $key => $value)[/code]I want to get a key named "name".Thank you. Quote Link to comment Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 foreach($_POST as $key => $value){ if($value == "name") { $selected = $key; break; } else { continue;} Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2006 Author Share Posted December 15, 2006 Thanks for that, but it isnt what i really need.Im trying to include a specific input field that has been posted to this script in a peice of SQL coding.In order to do that i need to do something like $key[name] but that doesnt work.Any ideas? Quote Link to comment Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 [quote]Im trying to include a specific input field that has been posted to this script in a peice of SQL coding.[/quote]I don't really understand what you mean, can you rephrase? Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2006 Author Share Posted December 15, 2006 [code]if (isset($_POST["submit"])) { foreach ($_POST as $key => $value) { if ($key != empty($value)) { if ($key != "submit") { $query = mysql_query("SELECT * FROM orders WHERE order_item = '$value'"); $check = mysql_num_rows($query); if(!$check) { mysql_query("insert into orders (order_item) values ('$value')",$con); } else { $query = mysql_query("SELECT order_quantity FROM orders WHERE order_item='$value'"); $data = mysql_fetch_assoc($query); $quantity = $data["order_quantity"]; $quantity = $quantity + 1; mysql_query("UPDATE orders SET order_quantity=$quantity WHERE order_item='$value'"); } } } } echo "Thank your for your order!"; }[/code]^^ that is what I have at the moment. Presently that code will input into the database the values into the order_items table. I want all the $values to go into the items field, except for the name field (that was submitted on a previous page). I want the name value to be inserted into the same row as the order_items. Very difficult to explain, but I want to achieve this:[code]mysql_query("insert into orders (order_item,order_name) values ('$value','THEVALUEOFTHENAMEFIELDONPREVIOUSPAGESHOULDBEINSERTEDHERE')",$con);[/code]hope that clears things up a little. Quote Link to comment Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 are you sure you can't just do:mysql_query("insert into orders (order_item,order_name) values ('$value','$key')",$con);I think that will work... Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2006 Author Share Posted December 15, 2006 No, because $key is the value of all the input field names on the previous page. So I would end up getting "name,order1,order2,order3,order4,order5" all put into the order_name field. Whereas I just want the value of the "name" $key added. Quote Link to comment 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.