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?
loginsystem. Not the part of the SQL query.