This question already has an answer here:
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP 28 answers
I'm new to PHP and MySql. I am trying to connect to MySql database and display its contents on screen. But nothing is displaying out. Though I am able to get "congrats" message for connection, I am not able to get anything else. Please help me out to figure out what is the problem with my code.
<?php
$dbhost= "localhost";
$dbuser= "root";
$dbpass= "";
$dbconnect= mysqli_connect('$dbhost', '$dbuser', '$dbpass','$mydb');
/*mysqli_select_db($mydb);*/
if(!mysqli_select_db){
echo "database not found";
die(mysqli_error());
}
else{
echo "congrats";
}
$query = "SELECT * FROM userinfo";
$result = mysqli_query($dbconnect, $query);
while($record = mysqli_fetch_array($result)){
echo $record['Name'], $record['Email'], $record['Contact'];
}
?>