The problem has been fixed by using serialize in ajax. This information is fixed.
I made a form to update exited data in the mysql table.
Without using ajax it's updating data successfully.
but with Ajax call i have a problem to pass name="id[]" and name="title[]".
These are input tags in the form
$sql = "SELECT * from table";
$results = mysqli_query($con, $sql);
<form name="form1" method="post" action="">
<?phpwhile($rows=mysqli_fetch_array($results)){ ?>
<input name="id[](at this point i am having problem)" type="hidden" id="id" value="<?php echo $rows['id']; ?>">
<input name="title[] (at this point i am having problem)" type="text" id="title" value="<?php echo $rows['title']; ?>">
<?php } ?> //closing while
<input type="submit" name="submit" value="Submit" id="save">
This ajax I am trying
$(document).on('click','#save',function(e) {
var data = $('form').serialize();
$.ajax({
data:data,
type: "post",
url: "add.php",
success: function(data){
alert("Data Save: " + data);
}
});
});
This is PHP (add.php)
$sql = "SELECT * from table";
$results = mysqli_query($con, $sql);
$count=mysqli_num_rows($results);
if(isset($_REQUEST)){
$count=count($_POST["id"]);
for($i=0;$i<$count;$i++){
$sql="UPDATE `title` SET `title` = '" . $_POST['title'][$i] . "' WHERE `id` ='" . $_POST['id'][$i] . "'";
$result1=mysqli_query($con, $sql);
}
echo $count;
//$sql = "UPDATE `title` SET `title`='$title' WHERE `title`.`id` =$id" ;
if(mysqli_query($con, $sql)){
echo "Updated";
}
else{
echo mysqli_error($con);
}
}