Echo data from database

Codes here !

Moderators: egami, macek, gesf

Post Reply
K1mBQ
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Apr 17, 2018 12:40 pm

Tue Apr 17, 2018 2:39 pm

Hi'
I am a PHP/SQL newbie and I have a very basic trouble with retrieving data from my database. I have made a connection and performed a succesful INSERT column code - the connection part must be OK. See below.

EX:

Code: Select all

<?php
$con=mysqli_connect("localhost","root","12345","DB");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Perform a query, check for error
if (!mysqli_query($con,"ALTER TABLE `Kalender 2017` ADD COLUMN `ID` INT AUTO_INCREMENT UNIQUE PRIMARY KEY FIRST"))
  {
  echo("Error description: " . mysqli_error($con));
  }

mysqli_close($con);
?>
However when I try to perform a query and echo the result I get nothing. The SQL code used in phpMyAdmin gets the desired result, but using the same code translated by phpMyAdmin to PHP I get nothing - "Connected successfully
0 results". I do think, it is a simple matter of proper syntax.

EX.

Code: Select all

<?php
$servername = "localhost";
$username = "root";
$password = "12345";
$dbname = "webvisionaire_d";
$txt = "Connected successfully";

$conn = mysqli_connect("localhost","root","12345","webvisionaire_d");
// Check connection �
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
echo "$txt";
echo "<BR>";
$sql = "SELECT * FROM `Kalender 2017` WHERE `Vært`= 'Ole'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "Uge Nr.: " . $row["Uge Nr."]. " - Dato: " . $row["Dato"]. " - V�rt: " . $row["V�rt"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>
Please help - Thank you in advance

chorn
php-forum Fan User
php-forum Fan User
Posts: 551
Joined: Fri Apr 01, 2016 2:18 am

Wed Apr 18, 2018 12:43 am

what do you get if you remove the condition?

Post Reply