www.webdeveloper.com
Results 1 to 3 of 3

Thread: Multi-update query...

  1. #1
    Join Date
    Nov 2002
    Location
    Scotland
    Posts
    550

    Exclamation Multi-update query...

    Hello,

    I have a list of checkboxes in my PHP page and a pic and link associated with each.

    Now, I need to be able to update all records checked/unchecked.

    The following is a small portion of my script:
    PHP Code:
    <?
    if (isset($_POST['submitted'])) {

    $id $_POST['current'];

    if ((
    $_SESSION['user_id'] == 1) || ($_SESSION['user_id'] == 2)) {

    foreach(
    $_POST['current'] as $key=>$value

    if(
    $key
    $checkValue="Y"
    else 
    $checkValue="N"

    $query "UPDATE footer_logos SET visible = '".$checkValue."' WHERE id = '".$value."' "

    if (!
    mysql_query($query)) 

      
    // The code, if the query not executed..
        
        
    echo 'query was not executed';
         

    }
        
    }

    $query1 "SELECT * FROM footer_logos";
    $result1 = @mysql_query($query1); // Run the Query.


    echo '<p><b>Edit "Footer Logos"</b></p>';

    echo 
    '<form name="form1" method="POST" action="update_logos.php" class="book">';

    echo 
    '<table width="550" border="0" style="padding:5px">';
      echo 
    '<tr style="background-color:#eaeaea;">
          <td>Visible</td>
        <td>Image</td>
        <td>Link</td>
        <td>ALT Text</td>
      </tr>'
    ;
    while (
    $row1 mysql_fetch_array($result1)) {

                
    $visible $row1['visible'];
                
    $id $row1['id'];

    echo 
    '<tr><td>';

    if (
    $visible=='Y') {$checked="checked";} 
    else{
    $checked="";} 

    echo 
    '<input type="checkbox" name="current[]" id="current[]" value="' $id '" class="maillistadd" '.$checked.' /></td>'
                
    echo 
    '<td><img src="../images/' $row1[1] . '" /></td>
    <td>' 
    $row1[2] . '</td><td>' $row1[4] . '</td>';
    echo 
    '</tr>';
    }    
        
    echo 
    '</table>';
        
    ?>       
                <br>
                <input name="submit" type="submit" class="submit" value="Update the 'Logos' box">
                <br>
                <br>
                <input type="hidden" value="form1">
                <input type="hidden" name="submitted" value="TRUE" />
                </p>
            </form><?
        
    include ('../include_files/afooterfile.html');

    ?>
    Is it easy to basically update all records(there's only 5 just now) and set 'visible' to either 'N' or 'Y' depending on whether the checkbox is checked or not.
    Upon submitting I get the following error:
    Code:
    Error!
    Notice: Query: 
    MySQL Error: Query was empty
    I've been racking my brains on this one for a few weeks now.


    Many thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    Scotland
    Posts
    550
    For the record, it outputs the checkboxes correctly i.e. those that are 'Y' are checked and those set to 'N' are unchecked.

  3. #3
    Join Date
    Nov 2002
    Location
    Scotland
    Posts
    550
    *bump*

    Apologies for the bump, but getting pretty desperate here.

    Surely it must be easy enough to do an UPDATE query for all records in the table and changing the value if the checkbox has been checked/unchecked.

    There's only 5 records in the table. Please help.

    Thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles