cocolino
-
Posts
8 -
Joined
-
Last visited
Posts posted by cocolino
-
-
Sorry, I don't understand what you're saying here.
I don't really want all the code, but it's becoming apparent that the problem most likely lies with a part of the code that you haven't identified. As such, to allow us to have a chance at finding it we need to have visibility of it all (for example, you have cut the top off the decision logic that applies to the behaviour of the page in relation to the variables in question and don't think that's a problem. In short, the problem does not lie in the code that you have posted already (at least not solely) so we need to see more.
As a beginner you shouldn't want solutions that you don't understand from other people to fix problems you couldn't properly identify - you should want people to help you to understand the problem and create your own solution to it once you have learned where it went wrong - which is exactly what mac_gyver the other people of this board are going to be: those people who can help you learn and grow. If you just want someone to do it for you you want the freelance board where you can recruit someone to do the task for you.
Here is all code from file.php
<?php session_start(); require ('login.php'); if ($user['status'] != '1' || $user['group'] != '2') { header('Location: '. $s['url'] .'/enter.php'); exit(); } $action = $_GET['select']; if ($action == 'categories') { $categories = array (); $categories_query = mysql_query("SELECT * FROM categories ORDER BY name"); while ($categories_row = mysql_fetch_array($categories_query)) { $categories[] = array ( 'id' => $categories_row['catid'], 'name' => $categories_row['name'], 'title' => $categories_row['title'], 'url' => $categories_row['url'], 'icon' => $categories_row['icon'], 'description' => $categories_row['description'] ); } categories_admin(); } elseif ($action == 'edit_category') { $category_id = (int) $_GET['categ']; if (isset($_POST['submit_edit_category'])) { $edit_category_query = mysql_query("UPDATE categories SET name = '". $_POST['name'] ."', description = '". $_POST['description'] ."' WHERE catid = '". $category_id ."'"); // categories sidebar $delete_category_query = mysql_query("delete FROM map_category WHERE catid2 = '". $category_id ."'"); if (empty($_POST['check_list'])) {echo '';} if (is_array($_POST['check_list'])) { foreach ($_POST['check_list'] as $selected) { $insert_category_query = mysql_query("INSERT INTO map_category(catid1, catid2) VALUES ('". $category_id ."','". $selected ."')"); } } // categories footer $delete_category_query = mysql_query("delete FROM map_category_footer WHERE catid2 = '". $category_id ."'"); if (empty($_POST['check_list_footer'])) {echo '';} if (is_array($_POST['check_list_footer'])) { foreach ($_POST['check_list_footer'] as $selected) { $insert_category_query = mysql_query("INSERT INTO map_category_footer(catid1, catid2) VALUES ('". $category_id ."','". $selected ."')"); } } redirect_page('/admin/file.php?select=edit_category&categ='. $category_id); } $category_query = mysql_query("SELECT * FROM categories WHERE catid = '". $category_id ."' LIMIT 1"); $category_row = mysql_fetch_assoc($category_query); $edit_category = array ( 'name' => $category_row['name'], 'description' => $category_row['description'] ); // select categories sidebar $top_category_query = mysql_query("SELECT c.catid, c.name, (CASE WHEN mc.catid1 IS NULL THEN 0 ELSE 1 END) AS is_selected FROM categories c LEFT JOIN map_category mc ON c.catid = mc.catid2 and mc.catid1 = '". $category_id ."' WHERE c.catid <> '". $category_id ."' ORDER BY c.name ASC "); while($top_category_row = mysql_fetch_assoc($top_category_query)) { $top_edit_category[] = $top_category_row; } // select categories footer $top_category_footer_query = mysql_query("SELECT c.catid, c.name, (CASE WHEN mc.catid1 IS NULL THEN 0 ELSE 1 END) AS is_selected FROM categories c LEFT JOIN map_category_footer mc ON c.catid = mc.catid2 and mc.catid1 = '". $category_id ."' WHERE c.catid <> '". $category_id ."' ORDER BY c.name ASC "); while($top_category_footer_row = mysql_fetch_assoc($top_category_footer_query)) { $top_edit_category_footer[] = $top_category_footer_row; } edit_category_admin(); } ?>
-
So looking at the problem logically (because we don't have all the code) The issue happens on page reload/refresh and only effects checkboxes that have been checked. Therefor the issue is with if(isset(...)) checks (or perhaps a lack there of) and relates to how you render the previously entered form information to the page.
I suspect you have some logic that takes the checked boxes and adds them to the form for persistence? So that whatever get's checked stays checked after the form is submitted or page refreshed?
But what you are doing is rendering the element every time in addition to the previous full form elements. Instead of this you should be using it to alter the existing elements to being "checked".
Chances of seeing the rest of the code?
Hi, i understand your opinion but this part of code make a action for that request. Way you want all code?
-
unfortunately the OP didn't actually answer the question that was asked.
the problem is most likely because his code/database design allows multiple rows with the same combination of values to be inserted into his database table.
your database table needs to enforce uniqueness. you need to define a unique composite index for the (catid1, catid2) columns so that you can only insert one row for any combination of values. you should also give those columns names that indicate their true purpose so that anyone reading the code/query can understand what the values mean.
Thanks but i want solutions because i'm beginner and don't know what to do in the code!
-
it's not clear what the issue is. what update are you talking about? you have an UPDATE query, but i suspect you are talking about the INSERTed data or are you talking about just refreshing the page?
in general, when asking for help, since we are not sitting there with you, you need to show what result you are getting and at what point you are getting it, and either clearly state or show what is wrong with that result, and also show or state what result you expected to get.
Wen i update the page. every time wen i push submit button the checkboxes selected is duplicate.
Here is the printscreen of issue.
Thanks!
-
I don't want to sound nasty, but duplicate form elements on page refresh is the least of your problems.
What have you tried so far to fix it?
Did you piss some code from the start of the files.php because it seems to be starting with an elseif which makes no sense.
I'm beginner and i hope to get answer from advanced members.
The code from file start with elseif because that is the code witch make the call of execute... i don't see the sense to post entire code.
-
because that is the code witch make the call of execute... i don't see the sense to post entire code. thanks
-
Hello, my name is Terry and i'm new here.
I hope to find the best answear from experts!
-
Hello, i have the following problem with checkbox option...
Wen i have selected one or more checkboxes and update a page the checkbox return same values doubled, tripled or how many time is page updated.
I want to resolve this error. Can anybody help me?
Here is the 2 files, file.php and template.php
the file.php code
<?php elseif ($action == 'edit_category') { $category_id = (int) $_GET['categ']; if (isset($_POST['submit_edit_category'])) { $edit_category_query = mysql_query("UPDATE categories SET name = '". $_POST['name'] ."', description = '". $_POST['description'] ."' WHERE catid = '". $category_id ."'"); // categories sidebar $delete_category_query = mysql_query("delete FROM map_category WHERE catid2 = '". $category_id ."'"); if (empty($_POST['check_list'])) {echo '';} if (is_array($_POST['check_list'])) { foreach ($_POST['check_list'] as $selected) { $insert_category_query = mysql_query("INSERT INTO map_category(catid1, catid2) VALUES ('". $category_id ."','". $selected ."')"); } } // categories footer $delete_category_query = mysql_query("delete FROM map_category_footer WHERE catid2 = '". $category_id ."'"); if (empty($_POST['check_list_footer'])) {echo '';} if (is_array($_POST['check_list_footer'])) { foreach ($_POST['check_list_footer'] as $selected) { $insert_category_query = mysql_query("INSERT INTO map_category_footer(catid1, catid2) VALUES ('". $category_id ."','". $selected ."')"); } } redirect_page('/admin/file.php?select=edit_category&categ='. $category_id); } $category_query = mysql_query("SELECT * FROM categories WHERE catid = '". $category_id ."' LIMIT 1"); $category_row = mysql_fetch_assoc($category_query); $edit_category = array ( 'name' => $category_row['name'], 'description' => $category_row['description'] ); // select categories sidebar $top_category_query = mysql_query("SELECT c.catid, c.name, (CASE WHEN mc.catid1 IS NULL THEN 0 ELSE 1 END) AS is_selected FROM categories c LEFT JOIN map_category mc ON c.catid = mc.catid2 and mc.catid1 = '". $category_id ."' WHERE c.catid <> '". $category_id ."' ORDER BY c.name ASC "); while($top_category_row = mysql_fetch_assoc($top_category_query)) { $top_edit_category[] = $top_category_row; } // select categories footer $top_category_footer_query = mysql_query("SELECT c.catid, c.name, (CASE WHEN mc.catid1 IS NULL THEN 0 ELSE 1 END) AS is_selected FROM categories c LEFT JOIN map_category_footer mc ON c.catid = mc.catid2 and mc.catid1 = '". $category_id ."' WHERE c.catid <> '". $category_id ."' ORDER BY c.name ASC "); while($top_category_footer_row = mysql_fetch_assoc($top_category_footer_query)) { $top_edit_category_footer[] = $top_category_footer_row; } edit_category_admin(); } ?>
and template.php code
<?php function edit_category_admin() {global $edit_category,$top_edit_category,$top_edit_category_footer; main_header(); main_menu(); echo'<div id="center"><div id="admin"><h3>Edit category</h3>'; echo '<form action="" method="POST" name="form" onsubmit="return verify_add()"> <div class="left">Name</div> <div class="right"><input type="text" name="name" size="55" value="'. $edit_category['name'] .'" /></div> <div class="clear"></div> <div class="left">Description</div> <div class="right"><textarea name="description" rows="5" cols="95">'. $edit_category['description'] .'</textarea></div> <div class="clear"></div> <div class="left">Sidebar Category:</div> <div class="right"><div id="cat" style="background-color:#fcfebc;width: 100%px;height: 400px;overflow: scroll;">'; foreach ($top_edit_category as $top_cat) { echo '<label><input type="checkbox" name="check_list[]" value="'. $top_cat['catid'] .'" '. ($top_cat['is_selected'] == '1' ? 'checked' : '') .' /> '. $top_cat['name'] .'</label>'; } echo '</div></div> <div class="clear"></div> <div class="left">Footer Category:</div> <div class="right"><div id="cat" style="background-color:#DAF7A6;width: 100%px;height: 200px;overflow: scroll;">'; foreach ($top_edit_category_footer as $top_cat) { echo '<label><input type="checkbox" name="check_list_footer[]" value="'. $top_cat['catid'] .'" '. ($top_cat['is_selected'] == '1' ? 'checked' : '') .' /> '. $top_cat['name'] .'</label>'; } echo '</div></div> <div class="clear"></div> <div align="center"> <input type="submit" name="submit_edit_category" value="Edit category" /> </div><br /> </form>'; echo '</div></div> <div class="clear"></div>'; main_footer(); } ?>
Many thanks!
Checkbox problem
in PHP Coding Help
Posted
I resolve my problem.
Thank you for your time @mac_gyver !