Jump to content

Recommended Posts

Hello,

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:

<?php
$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>";
	}
 
	}else{
		echo '0 results';
	}

mysql_free_result($myout);
mysqli_close($conn);
?>

What is failing?

 

Thanks in advance for the assistance.

Link to comment
https://forums.phpfreaks.com/topic/311454-query-not-bringing-data/
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.

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

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

EDIT: and where is $myout defined?

Edited by Barand
  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

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