Jump to content

Query not bringing data

Recommended Posts


I hope all of you are safe with your families.

Currently I am starting with PHP Coding and I am trying to do a simple query to MySQL DB using PHP but even when is able to bring the number of rows is not displaying the values in the DB.

This is my code:

$servername = "localhost";
$database = "mydbtest";
$username = "root";
$password = "root";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
//echo "Connected successfully";
$myquery = "SELECT * FROM Country";
$result = $conn->query($myquery);
$numf = $result->num_rows;
echo "Number of rows " . $numf . "<br>";
if($numf >0){
	while($row = $result->fetch_object()){
		echo "Code" . $row->countrycode . "<br>";
		echo "Country" . $row->countryname . "<br>";
		echo '0 results';


What is failing?


Thanks in advance for the assistance.

Link to post
Share on other sites
44 minutes ago, emontcol said:

I am starting with PHP Coding

to get php to help you, find the php.ini that php is using and set error_reporting to E_ALL, display_errors to ON, and output_buffing to OFF. stop and start your web server to get any changes made to the php.ini to take effect. you should then be getting some php errors when you run your code that will help you find what the problem is.

Link to post
Share on other sites

To see if you have any mysql errors, put this line immediately before the line calling mysql_connect()


EDIT: and where is $myout defined?

Edited by Barand
Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.