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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:04:29+00:00 2026-05-28T11:04:29+00:00

Brief: Based on a query, I have multiple checkboxes generated dynamically. The value of

  • 0

Brief:

Based on a query, I have multiple checkboxes generated dynamically. The value of each checkbox is a string from one of the query’s rows;

upon form submission, another script is ran (del.php). This script gets the array of checkboxes that were checked and loops through them so it can ran another two queries, which is the delete and update queries.

They don’t work! if I try the INSERT query, it works fine. But the DELETE AND UPDATE don’t.

Here is my code:

index.php:

<?php
$gettips = mysql_query('SELECT body FROM tips WHERE body!="" and approved!="yes" and approved!="no"')or die(mysql_error());
$i=0;
while($tips = mysql_fetch_array($gettips))
{ ?>
<input type="checkbox" name="checkboxes[]" value="<?php print $tips[0] ?>" />
<input type="checkbox" name="checkboxesno[]" value="<?php print $tips[0] ?>" />
<a class="names"> - <span><?php print $tips[0] ?></span></a><br />
<?  $i++;
}
?>

and del.php :

foreach($_POST['checkboxes'] as $check) {
mysql_query("INSERT INTO approved (body) VALUES ('$check') ");
mysql_query("UPDATE tips SET approved='yes' WHERE body='$check'");      
}
foreach($_POST['checkboxesno'] as $key) {
mysql_query("DELETE FROM tips WHERE body='$key' ")or die(mysql_error());
}

mysql_error() doesn’t throw any errors. Database connection works in both files. The values of the checkboxes are strings. I’m able to delete the record by adding the string itself rather than the POST $variable to the query.
(I have also noticed that I’m not able to delete older records, only the newly added ones).

UPDATE:

I realized that trying to delete records where row='string' wasn’t the best practice, at least in my case. So, instead of passing strings as values to the checkboxes in the form, I decided to give the id value of the table.

here is the new code:

<?php
$gettips = mysql_query('SELECT id,body FROM tips WHERE body!="" and approved!="yes" and approved!="no"')or die(mysql_error());
$i=0;
while($tips = mysql_fetch_array($gettips))
{ ?>
<input type="checkbox" name="checkboxes[]" value="<?php print $tips[0] ?>" />
<input type="checkbox" name="checkboxesno[]" value="<?php print $tips[0] ?>" />
<a class="names"> - <span><?php print $tips[1] ?></span></a><br />
<?  $i++;
}
?>

and the delete queries:

foreach($_POST['checkboxes'] as $check) {
// echo "INSERT INTO approved (body) VALUES ('$check') <br>";
// echo "UPDATE tips SET approved='yes' WHERE body='$check'<br>";
mysql_query("INSERT INTO approved (body) VALUES ('$check') ");
mysql_query("UPDATE tips SET approved='yes' WHERE body='$check'");      
}

foreach($_POST['checkboxesno'] as $key) {
// echo "DELETE FROM tips WHERE id=$key <br>";
mysql_query("UPDATE tips SET approved='no' WHERE id=$key");      
mysql_query("DELETE FROM tips WHERE id=$key ")or die(mysql_error());
}

I still don’t know why the other way wasn’t working, so if someone out there has a chance to explain, it would be awesome!

  • 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-28T11:04:30+00:00Added an answer on May 28, 2026 at 11:04 am

    If you add some echo statements to your forloops and comment out the queries, you’ll be able to see what exactly is being sent to mysql, and then you’ll be better able to solve your problem.

    foreach($_POST['checkboxes'] as $check) {
      echo "INSERT INTO approved (body) VALUES ('$check') <br>";
      echo "UPDATE tips SET approved='yes' WHERE body='$check'<br>";
      //mysql_query("INSERT INTO approved (body) VALUES ('$check') ");
      //mysql_query("UPDATE tips SET approved='yes' WHERE body='$check'");      
    }
    
    foreach($_POST['checkboxesno'] as $key) {
      echo "DELETE FROM tips WHERE body='$key' <br>";
      //mysql_query("DELETE FROM tips WHERE body='$key' ")or die(mysql_error());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From a brief look using Reflector, it looks like String.Substring() allocates memory for each
I have a php page that creates page data from two .txt files (one
Brief I have an installation package (MSI based) which attempts to register a dll
i need to implement this scenario Brief about that is have two java based
In brief: Is it ever excusable to have assembly names and class names stored
I've this brief snippet: String target = baseFolder.toString() + entryName; target = target.substring(0, target.length()
My prob in brief: I have two tables namely category and product. table: category
Here is a brief summary of my aims. I have a list of data
I'm testing calling a SOAP based service from a .net client app and am
I'm a little stumped on this one. Anyone have any ideas? I'll try to

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.