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

  • Home
  • SEARCH
  • 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 9098827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:27:25+00:00 2026-06-17T00:27:25+00:00

Good evening, I’m trying to make a single php page wich can edit/delete multiple

  • 0

Good evening, I’m trying to make a single php page wich can edit/delete multiple rows in mysql:

<html>  
<head>  
<title>Update/Delete Test Page</title>  
</head>  
<body> 

<?  
include 'connect.php';

if(isset($_POST['edit'])) // from button name="delete"
{
    $title = $_POST['title'];
    $description = $_POST['description'];
    if(!empty($_POST['checkbox'])) {
    foreach($_POST['checkbox'] as $check) {
        $ed = $check;
        $sql = "UPDATE events SET title = '$title', description ='$description' WHERE id = $ed";  
    }
    }

if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con);
}
    ?>

<?php
include ("connect.php");

if(isset($_POST['delete'])) // from button name="delete"
{
    if(!empty($_POST['checkbox'])) {
    foreach($_POST['checkbox'] as $check) {
        $del = $check;

        $sql = "DELETE from events where id = $del";
        $result = $mysqli->query($sql) or die(mysqli_error($mysqli));
}
}
?>  

<?php
include 'connect.php';
$query = 'SELECT id, title, description FROM events WHERE evdate = "1/9/2013" order by title asc';
$result2 = $mysqli->query($query) or die(mysqli_error($mysqli));

echo '<br><br><br>';
echo '<b><div align="center"> "1/9/2013"</div></b>';

if ($result2) {

  // create a new form and then put the results
  // into a table.
  echo "<form method='post' action=".$_SERVER['PHP_SELF'].">"; 
  echo "<table cellspacing='0' cellpadding='3'>
    <th align='left'>Interval orar</th>
    <th align='left'>Eveniment</th>
    <th align='left'></th>
    ";

  while ($row = $result2->fetch_object()) {

    $title  = $row->title;
    $description = $row->description;
    $id     = $row->id;

    //put each record into a new table row with a checkbox
echo "
    <tr>
        <td align='left'><input type='text' name='title' size='20'  value='$title'></td>
        <td align='left'><input type='text' name='description' size='50'  value='$description'></td>
        <td align='left'><input type='checkbox' name='checkbox[]' id='checkbox[]'  value=$id />
     </tr>

     "; 
}

// when the loop is complete, close off the list.
echo "</table>
<p>
<input id='edit' type='submit' class='button' name='edit' value='Edit'/> 
<input id='delete' type='submit' class='button' name='delete' value='Delete'/>
</p>
</form>";
}   
?>
</body>  
</html>

Connect.php looks like this:

<?php
$db_host = "localhost";
$db_username = "calendar";
$db_pass = "calendar";
$db_name = "ecalendar";
$con = mysql_connect ("$db_host", "$db_username", "$db_pass") or die ("could not connect to     mysql database");
mysql_select_db("$db_name") or die ("no database");

$mysqli = new MySQLi($db_host, $db_username, $db_pass, $db_name) or die(mysqli_error());
?>

The delete works fine, but the edit doesn’t do anything…

Table looks like this:

Start/End Time         Event     (Checkbox is here)
08:00-10:00            test1               X
10:00-12:00            test2               X

When I try to edit test2 to test2xx I get this in Firebug POST :

title=08%3A00-10%3A00&description=test1&title=10%3A00-12%3A00&description=test2xx&checkbox%5B%5D=53&edit=Edit

If I delete I get this (and it works)

title=08%3A00-10%3A00&description=test1&title=10%3A00-12%3A00&description=test2&checkbox%5B%5D=53&delete=Delete

Edit works but only for the last row (test2), if I try to edit the row above (test1), it insted updates it with the values of the last row (test2)

  • 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-06-17T00:27:26+00:00Added an answer on June 17, 2026 at 12:27 am

    gave up on the code above and went with this example from

    http://bohemiawebsites.com/PHP-MYSQL-Update-Multiple-Rows.html
    

    Everything works if anybody needs it…

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

Sidebar

Related Questions

Good evening, I made a well working function with php, mysql and ajax. A
Good evening guys. I'm currently trying to get started on development of a project
Good evening, i hope you can help me with this problem, as I'm struggling
Good evening, I am having a weird issue with a method I am trying
Good evening, In a test JSF 2.0 web app, I am trying to get
Good evening, I must make an intranet with Liferay, the most important is to
Good evening ! I am wondering if Excel provides a built-in function that can
Good evening all, I'm trying to implement jquery table sorter, all seems fine and
Good evening, people! I'm trying to solve a rather simple problem, but.. well, it
Good evening everybody! I'm stuck at writing my own email program in php for

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.