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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:34:40+00:00 2026-05-24T13:34:40+00:00

I have following example of the PHP/SQL which worked perfectly when editing one row

  • 0

I have following example of the PHP/SQL which worked perfectly when editing one row & saving changes.

It is working based on POST/GET method – where URL is setting up which row ID to edit / save.

form -> post id & live values

seperate php file -> get 'id' and change row with this 'id'.

<?php

session_name('users');
session_set_cookie_params(2*7*24*60*60);
session_start();

define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';

if(!$_SESSION['id']) {
    header ("Location: index.php"); 
}


//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }

    return mysql_real_escape_string($str);
}

//Sanitize the POST values
$id = clean($_POST['id']);
$usr2 = $_SESSION['usr'];
$live = (isset($_POST['live']))?1:0;
$updated = date("F j, Y, g:i a",time()+60*60);
$title = clean($_POST['title']);
$content = clean($_POST['content']);

//Create INSERT query
$qry = "UPDATE table SET live = '$live' WHERE id='".mysql_real_escape_string($_POST['id']). "'  ";
$result = mysql_query($qry);
echo mysql_error();

//Check whether the query was successful or not
if($result) {
    header("location: notes.php");
    exit();
}else {
    die("Query failed");

}

?>

My question is how to update multiple rows table/form like this one?

  • 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-24T13:34:41+00:00Added an answer on May 24, 2026 at 1:34 pm

    The best way to do it is with a simple for loop.

    foreach ($_POST as $key=>$value) {
        // You didn't provide the names of the fields, so you will need to validate them here yourself.
        // I usually name them with a prefix, like somefield_3, and then I can use substr() to determine if the field is the one I'm looking for.
    
        $result=mysql_query("UPDATE whatever SET somefield=1 WHERE id=" . mysql_real_escape_string($key) . ";");
    
        //etc., etc.
    }
    

    Since you are only setting one boolean field, you could also do something like this:

    UPDATE table SET live=1 WHERE id IN (1,2,3,4,5);
    

    But I’d recommend doing the loop, since you will inevitably need to update other fields at some point with this query.

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

Sidebar

Related Questions

I am trying to import an SQL dump via PHP. I have the following
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
I have tried using the obvious method as outlined in the following example but
I am a newbie to Python and have come across the following example in
Say for example I have the following string: var testString = Hello, world; And
I have the following PHP code doing a very simple select into a table.
I have the following PHP object but I'm struggling to get the array item
I have the following code in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$

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.