This is my script code
<script type="text/javascript">
function myFunction() {
var query = '?';
var str = $("form").serialize();
$("#results").text(query += str);
var x = $("#results").text();
return x;
}
$('#myButton').on('click',function(){
var jsonString = JSON.stringify(myFunction());
console.log(jsonString);
$.ajax({
url: 'insert_value.php',
data: jsonString,
contentType: 'application/json; charset=utf-8',
type: 'POST',
}).done(function(resp) {
$('#result').html(resp)
});
});
</script>
<?php
include('db.php');
$json = file_get_contents('php://input');
$data = json_decode($json);
print_r($data);
$result = mysqli_query($link,"SELECT value FROM combo1");
$num_rows = mysqli_num_rows($result);
//echo "$num_rows Rows\n";
if ($result->num_rows > 0) {
// output data of each row
$array = Array();
$array1 = Array();
while($row = $result->fetch_assoc()) {
//echo "<br> value: ". $row['value']. "<br>";
$array[] = $row['value'];
}
print_r($array);
}
$keys = array();
$values = array();
foreach($_GET as $key=>$value){
$keys[] = $key;
$values[] = $value;
}
$arrar1 = array_keys($_GET);
$arrar2 = array_values($_GET);
print_r($arrar1);
print_r($arrar2);
?>
?Gender=Female&id=704136006388169
my query string is like this so I need to split those and put them in array
like below :
arrar1 :Gender ,id
arrar2: Female,70413600638816
so how to do this? ?Gender=Female&id=704136006388169 my query string is like this so I need to split those and put them in array like below :
array1 :Gender ,id array2: Female,70413600638816
After splitting of this query I want insert these values into database table
like array1 values as column names and array2 as column values so how can I do this please help
eg :gender id Female 70413600638816