Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
function data($table){
global $realid;
global $UserData;
$url = "http://localhost/folder/api/$table/$realid";
$json_decode = json_decode(file_get_contents($url));
$UserData = get_object_vars($json_decode[$realid]);
}
data("users");
data("user_data");


i want to call a php function twice on the same page with different values bu it keep telling me Undefined index for users table ..... help
Posted

1 solution

Look into your JSON data! There is no such property $realid in it!!!
 
Share this answer
 
Comments
amineguesmi 24-Jun-14 10:20am    
here's how the code look like :
if(isLoggedIn())
{
$username = $_SESSION['userID'];
$database->select("id")->from("users")->where("username", "$username")->query();
$record = $database->fetch_object();
$id = ($record -> id);
$realid = $id - 1;

function data($table){
global $realid;
global $UserData;
$url = "http://localhost/folder/api/$table/$realid";
$json_decode = json_decode(file_get_contents($url));
$UserData = get_object_vars($json_decode[$realid]);
}
data("users");
data("user_data");

?>
"

Congratulations, you are now logged in!

id: <!--?php echo $UserData["id"]; ?-->

username: <!--?php echo $UserData["username"]; ?-->

email: <!--?php echo $UserData["email"]; ?-->

firstname: <!--?php echo $UserData["firstname"]; ?-->


<!--?php<br /--> }
?>
everything works fine but the only problem i got is the Undefined index for users table " $UserData["firstname"]; " i just want to call the function twice in the same time so i can extract data in the same time from the database ..... thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900