Witam po raz kolejny :|
Chcę z bazy wyciągnąć rekordy, ale nie idzie po mojej myśli...
Wyskakują takie błędy:
Notice:
Undefined variable: conn in funkcje.php on line 6
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in funkcje.php on line 6
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /funkcje.php on line 8
Brak artykułów
Jeśli ktoś wie jak to rozwiązać, a pewnie są takie osoby to proszę o pomoc.
connect.php
$servername = "---";
$username = "---";
$password = "---";
$dbname = "---";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully <br />";
funkcja do wyciągnięcia z bazy
include("connect.php");
function pokaArt()
{
$sql = "SELECT * FROM artykuly";
$result = mysqli_query($conn, $sql);
//var_dump(mysqli_error($result));
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$output .= '<div class="tytul">';
$output .= '<p class="font-weight-bold text-uppercase ml-0 mb-3 text-center text-md-left">';
$output .= $row["tytul"];
$output .= '</p>';
$output .= '</div>';
$output .= '<div class="obrazek">';
$output .= $row["obrazek"];
$output .= '</div>';
$output .= '<div class="zajawka">';
$output .= '<p>';
$output .= $row["zajawka"];
$output .= '</p>';
$output .= '</div>';
$output .= '<div class="news">';
$output .= '<p>';
$output .= $row["news"];
$output .= '</p>';
$output .= '</div>';
}
}
else
{
echo "Brak artykułów";
}
}
mysqli_close($conn);
no i index
include("funkcje.php");
pokaArt();