Hello
iwant a script in php i describe my problem below
i checked all the checkbox and updated after updating i am getting values from enable field but when i checked randomly i am not getting updating i am getting different values to be checked
Here's the code
/* For connecting database
connect.php
*/
/* database connection */
<?php
$con=mysqli_connect("localhost","root","","multiple");
if(mysqli_connect_errno())
{
echo "failed to connect".mysqli_connect_error();
}
?>
*/
<?php
error_reporting(E_ALL ^ E_NOTICE);
include_once("connect.php");
if(isset($_POST["submit"]))
{
$usersCount = count($_POST["id"]);
for($i=0;$i<=$usersCount;$i++) {
$query1=mysqli_query($con,"UPDATE multiple set enable='".$_POST["id1"][$i]."' where id='".$_POST["id"][$i]."'");
if($query1)
{
echo "updated";
}
}
}
?>
<html>
<head>
</head>
<body>
<form action="index.php" method="post">
<?php
include_once("connect.php");
$retrieve=mysqli_query($con,"select * from multiple ORDER BY id ASC ");
while($row=mysqli_fetch_array($retrieve))
{
$id=$row["id"];
$enable=$row["enable"];
?>
<input type="checkbox" name="id1[]" id="id1[]" value="enable" <?php if($enable=="enable") { echo 'checked' ; } ?> />
<input type="hidden" name="id[]" id="id[]" value="<?php echo $row["id"]; ?>" />
<?php
echo $row["name"];
?>
<?php
}
?>
</br></br>
<input type="submit" name="submit" id="submit" value="submit" />
</form>
</body>
</html>
/* sql dump file */
-- phpMyAdmin SQL Dump
-- version 4.1.12
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 08, 2014 at 05:23 PM
-- Server version: 5.6.16
-- PHP Version: 5.5.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `multiple`
--
-- --------------------------------------------------------
--
-- Table structure for table `multiple`
--
CREATE TABLE IF NOT EXISTS `multiple` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(255) DEFAULT NULL,
`lastname` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`enable` varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
) ;
--
-- Dumping data for table `multiple`
--
INSERT INTO `multiple` (`id`, `firstname`, `lastname`, `email`, `phone`, `enable`) VALUES
(3, 'ashish2', 'ashish2', 'ashish2', 'ashish2', 'enable'),
(4, 'ashish3', 'ashish2', 'ashish3', 'ashish2', 'enable'),
(5, 'anusha', 'anusha', 'anusha', 'anusha', ''),
(6, 'madiri', 'madiri', 'madiri', 'madiri', '');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;