
mrooks1984
Members-
Posts
82 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
mrooks1984's Achievements

Member (2/5)
0
Reputation
-
post multiple fields with the same name into a database
mrooks1984 replied to mrooks1984's topic in PHP Coding Help
yea realised now, tried adding this to the code now all fine, thanks so much for your help $price = $_POST['price'][$key]; $id = $_POST['option_value_id'][$key]; // execute your query $sql = "UPDATE store_option$variation_id SET title = '$title', price = '$price' WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); -
post multiple fields with the same name into a database
mrooks1984 replied to mrooks1984's topic in PHP Coding Help
thanks for your reply, i have tried this, but only the first field is changed in the database. function post_update_variation_value() { $option_id = mysql_real_escape_string($_POST['option_id']); $variation_id = mysql_real_escape_string($_POST['variation_id']); $product_name = mysql_real_escape_string($_POST['product_name']); foreach ($_POST['title'] as $key => $value) { $title = $value; $price = $_POST['price'][$key]; // execute your query $sql = "UPDATE store_option$variation_id SET title = '$title', price = '$price' WHERE id = '$key'"; $res = mysql_query($sql) or die(mysql_error()); } echo '<script>window.location="dashboard.php?page=store_variation"</script>'; } } -
post multiple fields with the same name into a database
mrooks1984 replied to mrooks1984's topic in PHP Coding Help
if i use this code, i get this message: Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\jubileeleather\site\admin\_class\store.php on line 654 $option_id = mysql_real_escape_string($_POST['option_id']); $variation_id = mysql_real_escape_string($_POST['variation_id']); $product_name = mysql_real_escape_string($_POST['product_name']); foreach($_POST['title'] as $key1 => $value1){ foreach($_POST['price'] as $key2 => $value2){ foreach($_POST['option_value_id'] as $key3 => $value3){ $sql = "UPDATE store_option$variation_id SET title = '$value1', price = '$value2' WHERE id = '$value3'"; $res = mysql_query($sql) or die(mysql_error()); } } } echo '<script>window.location="dashboard.php?page=store_variation"</script>'; } -
post multiple fields with the same name into a database
mrooks1984 replied to mrooks1984's topic in PHP Coding Help
thanks for your replies, is it does update fine, but each field has the last result -
post multiple fields with the same name into a database
mrooks1984 posted a topic in PHP Coding Help
hello, i am hoping someone can help, i have multiple post results that need to go one by one into a table heres the form i have: echo '<h2>Update Variation Values</h2>'; echo '<div id ="content_form">'; echo '<form method="post" action="">'; echo '<input type="hidden" name="option_id" value="' . $option_id . '">'; echo '<input type="hidden" name="variation_id" value="' . $variation_id . '">'; echo '<input type="hidden" name="product_name" value="' . $product_name . '">'; $sql = "SELECT * FROM store_option$variation_id WHERE product = '$product_name'"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($res)) { echo '<div id="content_title"><label for="title[]">Title:</label></div>'; echo '<div id="content_box"><input name="title[]" type="text" id="title" value="' . $row['title'] . '" /></div>'; echo '<div id="content_title"><label for="price[]">Price:</label></div>'; echo '<div id="content_box"><input name="price[]" type="text" id="price[]" value="' . $row['price'] . '" /></div>'; } echo '<div id="content_body"><input type="submit" name="post_update_variation_value" value="Save Values"></div></form>'; echo '</div>'; } heres my current code echo '<pre>',print_r($_POST,true); foreach($_POST['title'] as $key => $value){ if($value !=''){ $sql = "UPDATE store_option$variation_id SET title = '$value', price = '$price' WHERE product = '$product_name'"; $res = mysql_query($sql) or die(mysql_error()); } else { echo "Option $key is empty<br />"; } } its currently just doing the last result and filling up the database with that result, many thanks all. -
thanks for your responces, looks like it not possible the way i wanted too, i go away and have a rethink. thanks again all.
-
thanks for your responce, the issue is with this code it sometimes only has one value in the post see the code below. //Get option values foreach($_POST['option_value'] as $key => $value){ if($value !=''){ $product_option_values[] = array("option_value" => $value); } } so if i replicate this from your code: $arr_title = array("Colours","Values","Test","Something else"); $arr_opt = array("Black","76"); $arr_res = array_combine($arr_title, $arr_opt); foreach ($arr_res as $key => $value) { if($value == ''){ // skip empty values continue; } echo "Title: ".$key."\n"."Value: ".$value.'<br />'; } i get this error: Warning: array_combine(): Both parameters should have an equal number of elements in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 237 this is the main issue, is sometimes the values has less results then the title, so needs to unstead of looping the one value around all the titles, is just to stop when there isnt any more values.
-
thanks for the post, could you do a example so i can see what you mean please?
-
hello jesirose this was my code before, all i want it to do is stop looping when there are no values left, it currently get values from a form and puts the results into 2 arrays one is a list of all the titles ($product_option_title) and one is all the values ($product_option_value), the values are selected from a drop down menu, so sometimes there is less values then titles, but sometimes the values and the titles are the same. so again if say the values is black, the titles are color and size, if only color is selected in the drop down menu the value would only have the value black. So what it needs to do is go right there is only black in the value, get the title then stop the loop, instead of going color black, size black. hope i have explained it clear enough. as i said before in a post i don't think it needs merging into another array(might be wrong). //Create cart option $cart_option = ''; if (isset($product_option_values)) { foreach ($product_option_titles as $product_option_title) { foreach ($product_option_values as $product_option_value) { $cart_option .= $product_option_title['option_title']." : ".$product_option_value['option_value']." "; } } } print_r($product_option_titles); print_r($product_option_values); echo $cart_option;
-
this is the full code //merge together both arrays $new_cart_options =array_merge($product_option_titles,$product_option_values); //merged arrays //loop combined arrays foreach($new_cart_options as $options) //setting output inside variable $output= $options['option_title']." : ".$options['option_value']." "; //output option title and value. //making sure array is set and is not empty if(isset($output) && !empty($output)){ print_r($output); echo $output; }else{ print "Array is not set or is empty"; } i am getting this still: Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 : Black : Black this is 239: $output= $options['option_title']." : ".$options['option_value']." "; doesent seem to like this: $options['option_title'] or $options['option_value'] array print out is same as other post. thanks for your help so far
-
i am getting this: Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240 Colours : Colours : Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240 Test : Test : Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240 : Black : Black this is 240: $output= $options['option_title']." : ".$options['option_value']." ";
-
thanks for that, dident notice that, until you pointed it out, displaying fine now. i need to have a think how to get it displayed like i need it now title - value then if no value dont display the title this is the print array Array ( [option_title] => Colours ) Array ( [option_title] => Test ) Array ( [option_value] => Black ) Array ( [option_value] => Bacon ) for the other arrays i did in the script i just do this to show certain results echo $options['option_title']; when i do this i get this: Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 so how do i do this please?
-
strange i changed to to the $key = and i get: Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 0 = Array/n Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 1 = Array/n Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 2 = Array/n Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239 3 = Array/n
-
//merge together both arrays $new_cart_options =array_merge ($product_option_titles,$product_option_values); //merged arrays //loop combined arrays foreach($new_cart_options as $key => $value) { //print key value print $key.$value; } 239 is print $key.$value;
-
i am now getting this: Notice: Array to string conversion on line 239 0Array Notice: Array to string conversion on line 239 1Array Notice: Array to string conversion on line 239 2Array