Error in my first php code using GET

Douddirercild

New Member
I am writing my first server side api, and my code is giving me errors...Here is the php code (I am using a get method)\[code\]<?php //Check if there is a functionif(function_exists($_GET['function'])) { //If it equals loadAll if ($_GET['function']=='loadAll'){ //Then call the function and pass it the parameter it needs $_GET['function']($_GET['entity']); } //If found, call the function with value as a parameter $_GET['function']($_GET['value']);}/** * This method loads all of an object from the DB */function loadAll($entity){ //Variables for connecting to database. //These variable values come from hosting account. $hostname = "------"; $username = "-----"; $dbname = "-----"; //These variable values need to be changed by you before deploying $password = "-----"; //Connecting to your database mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); //Fetching from your database table. $query = "SELECT * FROM $entity"; $result = mysql_query($query); $myJson=array(); //Parse to array while($row = mysqli_fetch_array($result)){ $myJson[]=$row; } //Close connection mysqli_close($con); //Encode and send response echo json_encode($myJson);}?>\[/code\]My get URL is\[code\]http://someURL.com/api/index.php?function=loadAll&entity=School\[/code\]My errors are:\[code\]Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, resource given in D:\hosting\somenumber\html\api\index.php on line 42Warning: mysqli_close() expects parameter 1 to be mysqli, null given in D:\hosting\somenumber\html\api\index.php on line 47[]Fatal error: Function name must be a string in D:\hosting\somenumber\html\api\index.php on line 14\[/code\]I appreciate all your help
 
Top