I am fairly new to php and learning how to run sql queries using php.
So far I wrote following code:
<?php
$servername="localhost";
$user="root";
$password="mypassword";
$dbname="mydbname";
//Create Connection
$conn=mysqli_connect($servername,$user,$password,$dbname);
//Check connection
if(!$conn)
{
die("connection failed" . mysqli_connect_error());
}
echo "<b>Connection is Successfull.</b>";
mysqli_close($conn);
unset($conn);
$sql = "SELECT * FROM users";
$query=mysqli_query($conn, $sql) or die(mysql_error())
?>
When I run above code, it gives me following error
Connection is Successful.
Notice: Undefined variable: conn in /index2.php on line 34
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in index2.php on line 34
I have tried several other methods but all shows some kind of error.