0
\$\begingroup\$
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
\$\endgroup\$
1

2 Answers 2

1
\$\begingroup\$

no description....

no commands in the code.....

and this problem can be solved by reading the first pages of the php documentation....

http://php.net/

... ... ... ...

... ... ... ...

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);
 }
 }
 }
}
answered Apr 6, 2016 at 11:08
\$\endgroup\$
1
  • \$\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\$ Commented Apr 6, 2016 at 12:14
2
\$\begingroup\$
  • 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
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.