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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:43:28+00:00 2026-05-20T22:43:28+00:00

I have an issue where I need to be able to use check boxes

  • 0

I have an issue where I need to be able to use check boxes in order to delete and modify data in a mysql database.

What is the most efficient way of being able to use multiple submit buttons to either insert data based on what the user types into the text boxes, delete based on the check boxes selected, and modify based on the check boxes selected.

Here is the code I have so far:

 <?php 
$host       = "localhost";
$user       = "root";
$pass       = "";
$dbName     = "ticket_history";
$table_name = "ticket_history";

################ Connect to the Database and SELECT DATA ####################################
$conn = mysql_connect($host, $user, $pass) or die ("Unable to connect");
mysql_select_db($dbName);
$query = "SELECT Auto,Date,Ticket_Number,Description,Result FROM $table_name";
$result = mysql_query($query);
$count=mysql_num_rows($result);
#############################################################################################
?>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<table width=50%>
    <form method="post">
        <table width border='0'>
            <tr><td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date:<input type="text" name="date"/></td>
            <td>Ticket #:<input type="text" name="ticket"/></td></tr>
            <table>
                <tr><td>Description:<TEXTAREA COLS=50 name="description"></TEXTAREA></td></tr>
                <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result     :<TEXTAREA COLS=50 name="result"></TEXTAREA></td></tr>
            </table>
            <tr><td><input type="submit" name="create" value="Add"/></td></tr>
            <tr><td><input type="submit" name="delete" value="Delete"/></td></tr>
            <tr><td><input type="submit" name="modify" value="Modify"/></td></tr>
        </table>    
</table>

<?php
print "<table width=80% border=1>\n"; 
$cols = 0; 
while ($get_info = mysql_fetch_assoc($result)){ 
$id = $get_info['Auto'];
if($cols == 0) 
{ 
  $cols = 1; 
  print "<tr>";
  print "<th>Select</th>";  
  foreach($get_info as $col => $value) 
  { 
    print "<th>$col</th>"; 
  } 
  print "<tr>\n"; 
} 
print "<tr>\n"; 
print "<td><input type='checkbox' name='selected[]' id='checkbox[]' value=$id></td>";
foreach ($get_info as $field) 
print "\t<td align='center'><font face=arial size=1/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 

if (isset($_POST['create'])) {
    $query_insert = "INSERT INTO ticket_history (Date, Ticket_Number, Description, Result) 
                 VALUES ('$_POST[date]', '$_POST[ticket]', '$_POST[description]', '$_POST[result]')";
$result_insert = mysql_query($query_insert);
if ($result_insert) {
echo "win";
}
else {
echo "fail";
}

}
elseif (isset($_POST['delete'])) {
    $ids = array();
foreach($_POST['selected'] as $selected) {
    if (ctype_digit($selected)) {
        $ids[] = $selected;
    }
    else {
        die('invalid input');
    }
$sql_delete = sprintf('DELETE FROM ticket_history WHERE Auto IN (%s)', 
    implode(',', $ids));

$result_delete = mysql_query($sql_delete);
}
if ($result_delete) {
echo $result_delete;
}
else {
echo "fail";
}
}
elseif (isset($_POST['modify'])) {
    header('Location: modify_ticket.php');
}



mysql_close($conn);
?>
</form>

</BODY>
</HTML>

Insert.php
<?php
$host       = "localhost";
$user       = "root";
$pass       = "";
$dbName     = "ticket_history";
$table_name = "ticket_history";

$conn = mysql_connect($host, $user, $pass) or die ("Unable to connect");
mysql_select_db($dbName);


$query_insert = "INSERT INTO ticket_history (Date, Ticket_Number, Description, Result) 
                 VALUES ('$_POST[date]', '$_POST[ticket]', '$_POST[description]', '$_POST[result]')";
$result_insert = mysql_query($query_insert);
if ($result_insert) {
echo "win";
}
else {
echo "fail";
}
 #header( 'Location: ticket_history.php' ); 
?>



Delete.php

<?php
$host       = "localhost";
$user       = "root";
$pass       = "";
$dbName     = "ticket_history";
$table_name = "ticket_history";

################ Connect to the Database and SELECT DATA ####################################
$conn = mysql_connect($host, $user, $pass) or die ("Unable to connect");
mysql_select_db($dbName);
$query = "SELECT Date,Ticket_Number,Description,Result FROM $table_name";
$result = mysql_query($query);
$count=mysql_num_rows($result);
#####################################

$ids = array();
foreach($_POST['selected'] as $selected) {
    if (ctype_digit($selected)) {
        $ids[] = $selected;
    }
    else {
        die('invalid input');
    }
$sql = sprintf('DELETE FROM ticket_history WHERE Auto IN (%s)', 
    implode(',', $ids));

$result = mysql_query($sql);
}

 header( 'Location: ticket_history.php' ); 

?>

Any help is appreciated!

Thank you!

  • 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-20T22:43:28+00:00Added an answer on May 20, 2026 at 10:43 pm

    I would take the insert and delete code and put it on top of the main file instead of having them into files. the simplest way would be to submit the form to itself and based on the submit button clicked run the code block

    if($_POST['create']){
      // insert code
    }
    elseif($_POST['delete']){
      // delete code
    }
    

    continue the logic of if/else/elseif to handle all the cases. This strikes me as the simplest way to get done what you want to do.

    Edit:
    Not sure but seems like you are handling the $_POST[‘create’] etc after the HTML code. You should always do that sort of processing BEFORE the html rendering and even before the query to get the records you want to display, this way your get query will always bring up to date results.

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

Sidebar

Related Questions

I have a resource scheduling issue in Java where things need to be sequenced,
I need to be able to use the API for SugarCRM to exchange information
I’m having an issue where I need to be able to change a series
I need to IMPLEMENT(not to use some library/open source) an event/message system. I have
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue using the PEAR libraries on Windows from PHP . Pear
We have an issue related to a Java application running under a (rather old)
We have an issue on our page whereby the first time a button posts
I have some issue with a Perl script. It modifies the content of a
I have an issue with using AWK to simply remove a field from a

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.