-1

I can connect to DB but i cant echo , all time that said 0 results but my DB have TABLE (text) with 2 COLUMN id and text and i have inserted text in my table.

$con = mysqli_connect("localhost","1078362","nenaddurmisi022");

if (!$con) {

die("Connection failed: " . mysqli_connect_error());


}


$sql = "SELECT vesti FROM comment";

$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0)
{

// output data of each row

while($row = mysqli_fetch_assoc($result)) {

    echo  $row["vesti"]."<br>";

}

} 

else {

echo "0 results";

}



    mysqli_close($con);

2 Answers2

0

try

$sql = "SELECT * FROM text";

instead of

$sql = "SELECT text FROM text";

also be sure you'r table name is text.

one last thing you could try is to replace

echo  $row["text"]."<br>";

by

print_r($row);

to see if there's a result set from you'r Database

wmehanna
  • 394
  • 3
  • 15
0

You're using all mysqli functions except for your database connection. Try changing the first line to...

$con = mysqli_connect("localhost", "1078362", "nenaddurmisi022");

...and change the last line to...

mysqli_close($con);

I'm guessing there are a lot of errors generated by this script, but you're not seeing them. You should add these lines to the top of the script...

error_reporting(E_ALL);
ini_set('display_errors', 1);
Patrick Lee
  • 1,990
  • 1
  • 19
  • 24