Jump to content

silly function question


Jakebert

Recommended Posts

This is a silly question about functions. Why does this code:

 

<?php

//connect to the database
$host = "localhost";
$DBuser = "root";
$DBpassword = "";
$database = "ksu";

$connection = new mysqli($host, $DBuser, $DBpassword, $database);

if ($connection->connect_error) {
die('Connection Error (' . $connection->connect_errno . ') ' 
	. $mysqli->connect_error);
}

function getUserGroups($id) {

$query = $connection->query("SELECT group_id FROM group_membership WHERE user_id = " . $id); // this is line 20, where the error gets thrown
$results = mysqli_fetch_assoc($query);
return $results;
}


?>

 

Throw this error:

Notice: Undefined variable: connection in C:\wamp\www\KSU\connect.php on line 20

 

There must be a really obvious answer I'm missing.

Link to comment
https://forums.phpfreaks.com/topic/264719-silly-function-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.