\$\begingroup\$
\$\endgroup\$
1
if (isset($_POST["save-options"])) {
foreach ($names_of_array as $type => $value) {
update_option('updated_img', $_POST['show_img_url']);
if (isset($_POST["post0"])) {
update_option($names_of_array[0], true);
} else {
update_option($names_of_array[0], false);
}
if (isset($_POST["post1"])) {
update_option($names_of_array[1], true);
} else {
update_option($names_of_array[1], false);
}
if (isset($_POST["post2"])) {
update_option($names_of_array[2], true);
} else {
update_option($names_of_array[2], false);
}
if (isset($_POST["post3"])) {
update_option($names_of_array[3], true);
} else {
update_option($names_of_array[3], false);
}
if (isset($_POST["post4"])) {
update_option($names_of_array[4], true);
} else {
update_option($names_of_array[4], false);
}
}
}
HTML table is in form>>>>
<tr>
<td class="td-sample-settings"><input name="post0" value="<?php echo $names_of_array; ?>" type="checkbox" <?php echo (get_option("show_price") == true ? 'checked' : ''); ?> ></td>
<td class="td-sample-settings"><input name="post1" value="<?php echo $names_of_array; ?>" type="checkbox" <?php echo (get_option("show_width") == true ? 'checked' : ''); ?> ></td>
<td class="td-sample-settings"><input name="post2" value="<?php echo $names_of_array; ?>" type="checkbox" <?php echo (get_option("show_height") == true ? 'checked' : ''); ?> ></td>
<td class="td-sample-settings"><input name="post3" value="<?php echo $names_of_array; ?>" type="checkbox" <?php echo (get_option("show_weight") == true ? 'checked' : ''); ?> ></td>
<td class="td-sample-settings"><input name="post4" value="<?php echo $names_of_array; ?>" type="checkbox" <?php echo (get_option("show_color") == true ? 'checked' : ''); ?> ></td>
<td class="td-sample-settings"><input name="updated_img" type="button" id="insert-my-media" class="media-button button" value="Add my media"> </td>
<td class="td-sample-settings"><input name="show_img_url" type="text" class="next-button" id="set_imaged_id" value="<?php echo $_POST['show_img_url']; ?>" > </td>
</tr>
nhgrif
25.4k3 gold badges64 silver badges129 bronze badges
asked Apr 6, 2016 at 10:31
-
1\$\begingroup\$ Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does. You should also try to write a title that summarizes what your code does, not what you want to get out of a review. \$\endgroup\$301_Moved_Permanently– 301_Moved_Permanently2016年04月06日 11:19:35 +00:00Commented Apr 6, 2016 at 11:19
2 Answers 2
\$\begingroup\$
\$\endgroup\$
1
no description....
no commands in the code.....
and this problem can be solved by reading the first pages of the php documentation....
... ... ... ...
... ... ... ...
just copy and paste this...
if (isset($_POST["save-options"])) {
foreach ($names_of_array as $type => $value) {
update_option('updated_img', $_POST['show_img_url']);
for ($i=0; $i <= 4; $i++) {
if (isset($_POST["post$i"])) {
update_option($names_of_array[$i], true);
} else {
update_option($names_of_array[$i], false);
}
}
}
}
-
\$\begingroup\$ you will get more practice by solving these problems by thinking about an own solution. And you should learn more about this language here: php.net/manual/en/langref.php \$\endgroup\$Timemachine– Timemachine2016年04月06日 12:14:38 +00:00Commented Apr 6, 2016 at 12:14
\$\begingroup\$
\$\endgroup\$
- You are open to reflected XSS via
show_img_url
. You should always HTML encode user input when outputting it. - You don't really need to add the class to each cell. Just add it to the table to avoid duplication and increase readability.
- Your spacing and indentation is slightly off (the tr elements don't align, and the first td element has too many spaces)
answered Apr 6, 2016 at 16:53
default