Ошибка подключения базы данных к веб-сайту

Я пытаюсь подключить базу данных к моему сайту. У меня есть страница, на которой я хочу отображать категории из базы данных. Я вызываю функцию getPro () и получаю эту ошибку в результате. Я не могу понять, почему. Пожалуйста, просмотрите этот скриншот: https://imgur.com/a/Y4K93s2 Вы можете видеть, что технологии и бизнес перечислены, однако, технологии нет даже в моей базе данных …

Две ошибки:

Предупреждение: mysqli_query () ожидает, что параметр 1 будет mysqli, логическое значение указано в /opt/lampp/htdocs/updated/functions/functions.php в строке 24

Предупреждение: mysqli_fetch_array () ожидает, что параметр 1 будет mysqli_result, ноль указан в /opt/lampp/htdocs/updated/functions/functions.php в строке 26

<?php

$con = mysqli_connect("localhost","root","","jobconsc_content");

function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}

return $ip;
}

//getting the categories

function getCats(){

global $con;

$get_cats = "select * from categories";

$run_cats = mysqli_query($con,$get_cats);         //error 1

while ($row_cats=mysqli_fetch_array ($run_cats)){    //error 2

$cat_id=$row_cats['cat_id'];
$cat_title=$row_cats['cat_title'];

echo "<li><a href='index.html?cat=$cat_id'>$cat_title</a></li>";

}
}

function getPro(){

if(!isset($_GET['cat'])){

global $con;

$get_pro = "select * from posts order by RAND() LIMIT 0,6";

$run_pro = mysqli_query($con, $get_pro);

while($row_pro=mysqli_fetch_array($run_pro)){

$pro_id = $row_pro['post_id'];
$pro_cat = $row_pro['post_cat'];
$pro_title = $row_pro['post_title'];
$pro_image = $row_pro['post_image'];


echo "<div id='single_post'>

<h3 style='color:goldenrod;'> $pro_title </h3>

<img src='admin_area/post_images/$pro_image' width='180' height='180' />

<a href='index.html?add_cart=$pro_id'><button style='float:center'>Add to Cart</button></a>

</div>


";

}
}
}

function getCatPro(){

if(isset($_GET['cat'])){

$cat_id = $_GET['cat'];

global $con;

$get_cat_pro = "select * from posts where post_cat='$cat_id'";

$run_cat_pro = mysqli_query($con, $get_cat_pro);

while($row_cat_pro=mysqli_fetch_array($run_cat_pro)){

$pro_id = $row_cat_pro['post_id'];
$pro_cat = $row_cat_pro['post_cat'];
$pro_title = $row_cat_pro['post_title'];
$pro_image = $row_cat_pro['post_image'];


echo "<div id='single_post'>

<h3 style='color:goldenrod;'> $pro_title </h3>

<img src='admin_area/post_images/$pro_image' width='150' height='180'/>

<a href='index.php'><button style='float:centerß'>Add to Cart</button></a>


</div>


";
}
}
}
?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector