I am having an issue with a project I am working on dealing with SQL, i have a function that is taking a CSV file and reading it to insert it into a MySQL database.
function databaseWrite($filename)
{
$tableName = "";
$tableName = substr($filename, 0, -3);
echo $tableName;
$fp = fopen( $filename ,"r");
while ($line = fgets ($fp))
{
$arr = explode(",", $line);
$query = "INSERT INTO `".$tableName."` (Field1, Field2) VALUES (" . $arr[0] . "," . $arr[1] . ")";
//Use the mysql api to send those queries to the database
SQLQuery($query, $tableName);
}
fclose($fp);
}
it calls a SQL query function that actually does the query
function SQLQuery($query, $tableName)
{
global $con;
//first run a query to create the table name if it does not exist
mysqli_query($con,$query);
mysqli_close($con);
}
the problem is i am getting an error Warning: mysqli_query() expects parameter 1 to be mysqli, null given
I know my $con variable is correct because my dbconnect.php file works fine in my login function.
I have asked around and looked over the Internet and have not found a solution anywhere.