Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:47:05+00:00 2026-05-24T15:47:05+00:00

I have following HTML table: <form method=post action=update-table.php> <table class=table-data style=width: 960px;> <thead> <tr>

  • 0

I have following HTML table:

<form method="post" action="update-table.php">
    <table class="table-data" style="width: 960px;">
        <thead>
            <tr>
                <td class="sorting" rowspan="1" colspan="1" style="width: 193px;">ID</td>
                <td class="sorting" rowspan="1" colspan="1" style="width: 54px;">Live</td>

            </tr>
        </thead>
        <tbody>
            <tr class="odd">
                <td class="nth-1"><input type="text" value="12" name="id"></td>
                <td class="nth-2"><input type="checkbox" checked="checked" name="live"></td>

            </tr>
            <tr class="even">
                <td class="nth-1"><input type="text" value="11" name="id"></td>
                <td class="nth-2"><input type="checkbox" checked="checked" name="live"></td>

            </tr>
            <tr class="odd">
                <td class="nth-1"><input type="text" value="10" name="id"></td>
                <td class="nth-2"><input type="checkbox" checked="checked" name="live"></td>

            </tr>
        </tbody>
    </table>
<input type="submit" />

and I’m trying to update live values accordingly to the ids with this file:

<?php
# update
session_name('users');
session_set_cookie_params(2*7*24*60*60);
session_start();

define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';

if(!$_SESSION['id']) {
    header ("Location: index.php"); 
}


        //Function to sanitize values received from the form. Prevents SQL injection
        function clean($str) {
            $str = @trim($str);
            if(get_magic_quotes_gpc()) {
                $str = stripslashes($str);
            }
            return mysql_real_escape_string($str);
        }

        //Sanitize the POST values
        $id = clean($_POST['id']);
        //$usr2 = $_SESSION['usr'];
        $live = (isset($_POST['live']))?1:0;
        //$updated = date("F j, Y, g:i a",time()+60*60);

        //Create INSERT query
        foreach ($display_order as $id => $live) {
            $sql = "UPDATE news SET display_order = $live WHERE id = $id";
            $result = mysql_query($sql);

            if($result) {
                //header("location: notes.php");
                //exit();
                print_r($sql);
                print_r($display_order);
            }else {
                die("Query failed");

            }
        }
?>

But I’m getting an error:

Warning: Invalid argument supplied for foreach() in C:\Documents and Settings\USER\Desktop\Dropbox\wamp_at_work\update-table.php on line 33

Line 33 is: foreach ($display_order as $id => $live) {

What the problem? Any suggestions much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:47:06+00:00Added an answer on May 24, 2026 at 3:47 pm

    The problem is that you’re duplicating the ‘name’ attributes of the input elements. What you want to do is send arrays back to the server, ie:

    Updated with extended answer:

    <?php
    
    $inp_orders = !empty($_POST['live']) ? $_POST['live'] : array();
    
    // proccess post
    if ($inp_orders)
    {
            foreach ($inp_orders as $id => $live) {
                $id = (int) $id;
                $live = (bool) $live;
    
                // update orders
                $sql = "UPDATE news SET display_order = $live WHERE id = $id";
                $result = mysql_query($sql);
    
                    if($result) {
                        echo 'News updated';
                    }else {
                        die("Query failed");
                    }
            }
    }
    
    // get orders from db
    $res = mysql_select("SELECT * FROM news");
    $view_orders = array();
    
        while ($row = mysql_fetch_assoc($res))
        {
            $view_orders['id'] = $row['id'];
            $view_orders['live'] = $row['live'];
        }
    
    ?>
    
    
    <form method="post" action="">
        <table class="table-data" style="width: 960px;">
            <thead>
                <tr>
                    <td class="sorting" rowspan="1" colspan="1" style="width: 193px;">ID</td>
                    <td class="sorting" rowspan="1" colspan="1" style="width: 54px;">Live</td>
    
                </tr>
            </thead>
            <tbody>
                        <?php foreach ($view_orders as $order): $id = (int) $order['id']; $odd = true; ?>
                        <tr class="<?php echo $odd ? 'odd' : 'even' ?>">
                            <td class="nth-1"><?php echo $id ?></td>
                            <td class="nth-2"><input type="checkbox" <?php echo $order['live'] ? 'checked="checked"' : ''  ?> name="live[<?php echo $id ?>]" /></td>
                        </tr>
                        <?php $odd = $odd ? false : true; endforeach; ?>
            </tbody>
        </table>
        <input type="submit" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form setup: <html> <head></head> <body> <form method=post enctype=multipart/form-data action=FileUpload> <table>
If I have a html form like the following: <form name=statusForm action=post.php method=post enctype=multipart/form-data>
I have the following HTML table: <table style=width: 100%;> <tr> <td class=title_bar_left_border></td> <td class=title_bar_middle></td>
I have the following form: form <?php echo '<td><form action=episodesdelete.php method=POST>'; echo '<input type=hidden
I have the following form <form id=myform method=post action=#> <div class=fields> <fieldset class=ui-widget ui-widget-content
I have the following HTML: <div style=30px;> <table width=100%;> <tr> <td> <SELECT name=guidelinks> <OPTION
I have the following html code. <html> <body> <div style=max-width:1600px; min-width:900px; > <table> </table>
I have the following html code: <table> <tr> <td> <div id=fixmywidth style=position:relative; height:30px;> <div
Let's say I have the following HTML: <table id=foo> <th class=sortasc>Header</th> </table> <table id=bar>
If I have the following simplistic form: <?php class Application_Form_Contact extends Zend_Form { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.