etsted Posted March 27, 2014 Share Posted March 27, 2014 this is a little reference from my live chat script, but it wont work. The error message is variable $con is not defined, but it is clearly defined. $con = mysqli_connect("localhost","root","123","chat") or die(mysqli_error($con));function get_msg(){ $query = mysqli_query($con, "SELECT Sender, Message FROM chat"); $run = mysqli_query($con, $query); $messages = array(); while($message = mysqli_fetch_assoc($run)){ $messages = array('sender' => $message['Sender'], 'message' => $message['Message']); } return $messages; } Link to comment Share on other sites More sharing options...
Ingolme Posted March 27, 2014 Share Posted March 27, 2014 In PHP global variables are not accessible from inside functions unless you use the global keyword or $_GLOBALS array. You can read about variable scope here: http://es1.php.net/manual/en/language.variables.scope.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now