graham23s Posted July 15, 2008 Share Posted July 15, 2008 Hi Guy, my code below isnt working correctly! it doesnt show the fields update after i put new figures in: <?php case "edit-products-spreadsheet-mode": ########################### # EDIT PRODUCTS SPREADSHEET ########################### if (isset($_POST['submit_final'])) { foreach ($_POST['hidden_id'] as $key => $product_id) { $h_op = $_POST['hidden_op'][$key]; $h_np = $_POST['hidden_np'][$key]; // Query $q_update = "UPDATE `fcp_products` SET `product_price`='$h_op,`new_product_price`='$h_np' WHERE `id`='$product_id'"; print $q_update . "<br />"; } } if (isset($_POST['submit_c'])) { // Vars $c_i = mysql_real_escape_string($_POST['edit_cat_id']); // Do a query ready to loop $q_l = "SELECT * FROM `fcp_products` WHERE `category_id`='$c_i' ORDER BY `date_added` ASC"; $r_l = mysql_query($q_l); print("<form action=\"admin.php?page=edit-products-spreadsheet-mode\" method=\"post\">"); print("<table width='750' border='0' cellpadding='5' cellspacing='1' />\n"); print("<tr>\n"); print("<th>ID</th><th>Product Name</th><th>Original Price</th><th>Sale Price</th>\n"); print("</tr>\n"); // Loop while ($a_l = mysql_fetch_array($r_l)) { // Vars $p_id = $a_l['id']; $p_nm = $a_l['product_name']; $p_op = $a_l['product_price']; $p_np = $a_l['new_product_price']; // Print rows print("<tr><td align='center' class='td_style'><input type=\"hidden\" name=\"hidden_id[]\" value=\"$p_id\">$p_id</td><td align='left' class='td_style'>$p_nm</td><td align='center' class='td_style'><input type=\"hidden\" name=\"hidden_op[]\" value=\"$p_op\"><input type=\"text\" name=\"prod_op\" value=\"$p_op\" size=\"5\"></td><td align='center' class='td_style'><input type=\"hidden\" name=\"hidden_np[]\" value=\"$p_np\"><input type=\"text\" name=\"prod_op\" value=\"$p_np\" size=\"5\"></td></tr>\n"); } // end table print("<tr>\n"); print("<td class=\"td_style\" colspan='4' align='right'><input type='submit' name='submit_final' class='btn_style' value='Update!'></td>"); print("</tr>\n"); print("</table>"); print("</form>"); // Include the bottom part include("inc/inc-footer.php"); exit; } // Print the selection box print("<form action=\"admin.php?page=edit-products-spreadsheet-mode\" method=\"POST\">"); print("<table width='600' border='0' cellpadding='5' cellspacing='1' />\n"); print("<tr>\n"); print("<th colspan='3' align='center'>EDIT PRODUCTS - SPREADSHEET MODE</th>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class='td_style' align='left'>Select Category To Display & Edit:</td><td class='td_style' align='center'><select name=\"edit_cat_id\">"); // Cats $q_c = "SELECT * FROM `fcp_categories` ORDER BY `categoryname` ASC"; $r_c = mysql_query($q_c); // Loop while ($a_c = mysql_fetch_array($r_c)) { // Vars $category_id = $a_c['id']; $category_nm = $a_c['categoryname']; // Print print("<option value=\"$category_id\">$category_nm</option>"); } print("</select>"); print("</td><td class='td_style' align=\"right\"><input type=\"submit\" name=\"submit_c\" value=\"Display!\"></td>\n"); print("</tr>\n"); print("</table>"); print("</form>"); // Start getting the products from mysql $q_p = "SELECT * FROM `fcp_products`"; $r_p = mysql_query($q_p); break; ?> can anyone see any problems? thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/114904-updating-lots-of-fields-at-once/ Share on other sites More sharing options...
dannyb785 Posted July 15, 2008 Share Posted July 15, 2008 $q_update = "UPDATE `fcp_products` SET `product_price`='$h_op,`new_product_price`='$h_np' WHERE `id`='$product_id'"; first off, you didn't close the single quote after $h_op secondly, after this line, you are trying to output it to the screen. But to get it to do anything, you have to put it into the mysql_query() function. Fix those 2 and see what it does Link to comment https://forums.phpfreaks.com/topic/114904-updating-lots-of-fields-at-once/#findComment-590925 Share on other sites More sharing options...
cooldude832 Posted July 15, 2008 Share Posted July 15, 2008 use the standard debugging query structure of <?php $q = "Select * from `table`"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> and you can fix alot of your own errors Link to comment https://forums.phpfreaks.com/topic/114904-updating-lots-of-fields-at-once/#findComment-590945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.