Hello everyone, i am a PHP newbie but have some experience with other programming languages. I am trying to enter simple values into the database using the connection settings defined in a different file:
echo "Failed to connect to MySQL: " . mysqli_connect_error();
I have included this file in my entercategory.php file:
$insertQuery="insert into tbl_categories(CategoryName,CategoryDescription) values('$categoryName','$categoryDescription')";
die('Error entering to database'.mysqli_error($conn));
echo "Entered Successfully!";
Now, the system is complaining that the $conn is null ("mysqli_query() expects parameter 1 to be mysqli,null is given...").
What am i doing wrong here? Can someone please explain?
The function is called as follows:
I have put the code of DBConnect.php directly in entercategory.php. The $conn variable is not null and working just fine. However, i am not able to understand why, when the code in placed in a separate file (DBConnect.php), the $conn variable becomes null. Can someone please assist?