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 7602501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:25:41+00:00 2026-05-30T23:25:41+00:00

I am trying to filter use a form to filter a database then provide

  • 0

I am trying to filter use a form to filter a database then provide a way to update the filtered data. I may not being doing it the best way, but it is close to working. The problem seems to be that when I press the “Update” button, a few variables are cleared; count and ID.

I have fixed count by making it a session variable, but there isn’t a way to do it with ID. I am not sure why count gets erased, so I would appreciate if someone could tell me.

The update part of my code works perfectly when used without the filter part, again, the problem is that the id variable is empty. I have tested all other variables and put a constant in for ID for testing in my update statement. Here is my code.

<?php
session_start();
?>

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="inventory"; // Database name 
$tbl_name="computers"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form 
$school=$_POST['school'];
$make=$_POST['make'];
$model=$_POST['model'];
$barcode=$_POST['barcode'];
$location=$_POST['location'];
?>

    <?php
    include 'nav-bar.php';
    ?>

    <h2 align="center">Filter Computers</h2>
    <form name="form" method="post" style="margin: 0; text-align: center;">
    <p><label>School Name:</label><input type="text" name="school" size="8" id="school" tabindex="1"</p>
    <p><label>Make:</label><input type="text" name="make" size="25" id="make" tabindex="1"</p>
    <p><label>Model:</label><input type="text" name="model" size="25" id="model" tabindex="1"</p>
    <p><label>Barcode:</label><input type="text" name="barcode" size="12" id="barcode" tabindex="1"</p>
    <p><label>Location:</label><input type="text" name="location" size="25" id="location" tabindex="1"</p>
    <p><label>Serial:</label><input type="text" name="serial" size="25" id="location" tabindex="1"</p>
    <p><label>Date Acquired yyyy-dd-mm:</label><input type="text" name="date" size="8" id="location" tabindex="1"</p>
    <p><label>Processor:</label><input type="text" name="processor" size="25" id="location" tabindex="1"</p>
    <p><label>RAM:</label><input type="text" name="ram" size="25" id="location" tabindex="1"</p>
    <p><input align="center" type="submit" name="Filter" value="Filter">
    </form>

    <?php

    if($_POST['Filter']){
    $sql = "SELECT * FROM $tbl_name WHERE school like '%$school' AND make like '%$make' AND model like '%$model' AND location like '%$location'";
    $result=mysql_query($sql);

    // Count table rows 
    $count=mysql_num_rows($result);
    $_SESSION['count']=$count;


    ?>

    <strong>Update Multiple Computers</strong><br> 
    <table width="500" border="0" cellspacing="1" cellpadding="0">
    <form name="form1" method="post" action="">
    <tr> 
    <td>
    <table width="500" border="0" cellspacing="1" cellpadding="0">


    <tr>
    <td align="center"><strong>Id</strong></td>
    <td align="center"><strong>School</strong></td>
    <td align="center"><strong>Make</strong></td>
    <td align="center"><strong>Model</strong></td>
    <td align="center"><strong>Barcode</strong></td>
    <td align="center"><strong>Location</strong></td>
    </tr>

    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
    <td align="center"><input name="school[]" type="text" id="school" value="<?php echo $rows['school']; ?>"></td>
    <td align="center"><input name="make[]" type="text" id="make" value="<?php echo $rows['make']; ?>"></td>
    <td align="center"><input name="model[]" type="text" id="model" value="<?php echo $rows['model']; ?>"></td>
    <td align="center"><input name="barcode[]" type="text" id="barcode" value="<?php echo $rows['barcode']; ?>"></td>
    <td align="center"><input name="location[]" type="text" id="location" value="<?php echo $rows['location']; ?>"></td>
    </tr>

    <?php
    }
    ?>
    <tr>
    <td colspan="4" align="center"><input type="submit" name="Update" value="Update"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    <?php
    }
    // Check if button name "Update" is active, do this 
    if(isset($_POST['Update'])){
    for($i=0;$i<$_SESSION['count'];$i++){
    $sql1="UPDATE $tbl_name SET school='$school[$i]', make='$make[$i]', model='$model[$i]' , barcode='$barcode[$i]' , location='$location[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1);
    }
    session_destroy();
    }
    if(isset($result1)){
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=update_multiple.php\">";
    }
    ?>`

Any help is surely 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-30T23:25:42+00:00Added an answer on May 30, 2026 at 11:25 pm

    Please check this out…
    I have added two lines in your code and ID is being fetched and you can update data accordingly.
    I have commented as NOTE HERE..

    <?php
    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name="inventory"; // Database name 
    $tbl_name="computers"; // Table name
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // Get values from form 
    $school=$_POST['school'];
    $make=$_POST['make'];
    $model=$_POST['model'];
    $barcode=$_POST['barcode'];
    $location=$_POST['location'];
    //Note here
    $id = $_POST['id'];
    ?>
    
        <?php
        include 'nav-bar.php';
        ?>
    
        <h2 align="center">Filter Computers</h2>
        <form name="form" method="post" style="margin: 0; text-align: center;">
        <p><label>School Name:</label><input type="text" name="school" size="8" id="school" tabindex="1"</p>
        <p><label>Make:</label><input type="text" name="make" size="25" id="make" tabindex="1"</p>
        <p><label>Model:</label><input type="text" name="model" size="25" id="model" tabindex="1"</p>
        <p><label>Barcode:</label><input type="text" name="barcode" size="12" id="barcode" tabindex="1"</p>
        <p><label>Location:</label><input type="text" name="location" size="25" id="location" tabindex="1"</p>
        <p><label>Serial:</label><input type="text" name="serial" size="25" id="location" tabindex="1"</p>
        <p><label>Date Acquired yyyy-dd-mm:</label><input type="text" name="date" size="8" id="location" tabindex="1"</p>
        <p><label>Processor:</label><input type="text" name="processor" size="25" id="location" tabindex="1"</p>
        <p><label>RAM:</label><input type="text" name="ram" size="25" id="location" tabindex="1"</p>
        <p><input align="center" type="submit" name="Filter" value="Filter">
        </form>
    
        <?php
    
        if($_POST['Filter']){
        $sql = "SELECT * FROM $tbl_name WHERE school like '%$school' AND make like '%$make' AND model like '%$model' AND location like '%$location'";
        $result=mysql_query($sql);
    
        // Count table rows 
        $count=mysql_num_rows($result);
        $_SESSION['count']=$count;
    
    
        ?>
    
        <strong>Update Multiple Computers</strong><br> 
        <table width="500" border="0" cellspacing="1" cellpadding="0">
        <form name="form1" method="post" action="">
        <tr> 
        <td>
        <table width="500" border="0" cellspacing="1" cellpadding="0">
    
    
        <tr>
        <td align="center"><strong>Id</strong></td>
        <td align="center"><strong>School</strong></td>
        <td align="center"><strong>Make</strong></td>
        <td align="center"><strong>Model</strong></td>
        <td align="center"><strong>Barcode</strong></td>
        <td align="center"><strong>Location</strong></td>
        </tr>
    
        <?php
        while($rows=mysql_fetch_array($result)){
        ?>
        <tr>
        <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
        <td align="center"><input name="school[]" type="text" id="school" value="<?php echo $rows['school']; ?>"></td>
        <td align="center"><input name="make[]" type="text" id="make" value="<?php echo $rows['make']; ?>"></td>
        <td align="center"><input name="model[]" type="text" id="model" value="<?php echo $rows['model']; ?>"></td>
        <td align="center"><input name="barcode[]" type="text" id="barcode" value="<?php echo $rows['barcode']; ?>"></td>
        <td align="center"><input name="location[]" type="text" id="location" value="<?php echo $rows['location']; ?>"></td>
        <!-- Note here-->
        <input type="hidden" name="id[]" id="id" value="<?php echo $rows['id']; ?>" />
        </tr>
    
        <?php
        }
        ?>
        <tr>
        <td colspan="4" align="center"><input type="submit" name="Update" value="Update"></td>
        </tr>
        </table>
        </td>
        </tr>
        </form>
        </table>
        <?php
        }
        // Check if button name "Update" is active, do this 
        if(isset($_POST['Update'])){
        for($i=0;$i<$_SESSION['count'];$i++){
        $sql1="UPDATE $tbl_name SET school='$school[$i]', make='$make[$i]', model='$model[$i]' , barcode='$barcode[$i]' , location='$location[$i]' WHERE id='$id[$i]'";
        $result1=mysql_query($sql1);
        }
        session_destroy();
        }
        if(isset($result1)){
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=update_multiple.php\">";
        }
        ?>
    

    I hope that will help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying use a set of filter functions to run the appropriate routine,
I am trying to use the truncate filter on 2 variables (rsstitle and rssdescription),
I am trying to filter/search a database with ajax $.ajax({ type: POST, url: filterSearch.php,
Good Afternoon, I am trying to use the composite filter but in vain. While
I am trying to use a nested form but keep getting this error when
I am trying to use DataSet and DataAdapter to filter and navigate DataRows in
I have been trying to use the query functionality of the ItemFileReadStore to filter
I am trying to filter data in the dojo grid widget, however, I am
I am trying to use a filter to insert certain text into ScriptResource.axd that
I'm trying to make a data filter with php and to do so, I

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.