I have a php file which shows the username & password for a userID (via a mysql query). The userID is sent via jquery. I used json_encode to combine the username & password as an array. But when I attempt to extract the strings (username & password) from that combined (array) It seems that "whole array" was returned. How can I extract the strings (username & password) from a json_encoded array? These are my code snippets.
This is the file display.php
<?php
if(isset($_POST['id']))
{
$ID=$_POST['id'];
$userQuery = mysql_query("SELECT * FROM users WHERE userid ='".$ID."'");
$UserArray = mysql_fetch_array($userQuery);
$username=$UserArray[1];
$passWord=$UserArray[2];
$combinedArray = array($username,$passWord);
echo json_encode(combinedArray);
}
?>
This is the JQuery which gets the strings from the combined array...
<script type="text/javascript">
$.ajax({
type: "POST",
url: "display.php",
data:{id:userID},
success: function(returnedData)
{
$("#userNameDiv").html(returnedData);
$("#passWordDiv").html(returnedData);
}
});
</script>
And this is the combined array as it displays...
["anandan2345","appleMac2015"]
["anandan2345","appleMac2015"]
But I need these strings in two separate variables...
Could anyone suggest a way to do this?
mysql_xxx()functions in PHP are deprecated (and will be removed entirely in the next release of the language). You should stop using them, and switch to using either themysqliorPDOlibraries instead.