I'm stuck here for about 4 hours do alot of research and cannot fin the answer. I want to repopulate the table after updating the contents using jquery ajax and php so here is my code.
PHP script:
if(isset($_POST['myinputval']))
{
$uinput = $_POST['myinputval'];
$uinput = $mysqli->real_escape_string($uinput);
$query = ('INSERT INTO tbltest values (" ","'.$uinput.'") ');
if($mysqli->query($query))
{
} else
echo 'fail'. $mysqli->error;
}
$result= $mysqli->query("Select *from tbltest");
if($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{
$sendtojq[]=$row;
}
echo json_encode($sendtojq);
}
mysqli_close($mysqli);
Here is my script
<script type="text/javascript">
function ajaxsubmit()
{
var myinputval = $("#input1").val();
$.ajax({url:'myphp.php', type:'post', data:{
myinputval:myinputval
},
success: function(data)
{
alert(data);
}
});
}
</script>
This is the output when submitted
[{"ID":"1","NAME":".$newinput."},{"ID":"2","NAME":".$newinput."},{"ID":"3","NAME":".$newinput."},{"ID":"4","NAME":".$newinput."},{"ID":"5","NAME":".$newinput."},{"ID":"6","NAME":".$newinput."},{"ID":"7","NAME":"$newinput"},{"ID":"8","NAME":"twst"},{"ID":"9","NAME":"twst"},{"ID":"10","NAME":"testtt"},{"ID":"11","NAME":"testtt"},{"ID":"12","NAME":"thisssss"},{"ID":"13","NAME":"thisssss"},{"ID":"14","NAME":"tstet"},{"ID":"15","NAME":"Last"},{"ID":"16","NAME":""},{"ID":"17","NAME":"dddddddd"},{"ID":"18","NAME":"aaaaaaaaaaa"},{"ID":"19","NAME":"gggggggggggggggggggggg"},
Now what I want to do is get every single element of the array which is stored in the variable 'data' and use is at as the value of my table. Any suggestions? Thanks in advance.