<?php session_start(); ?> <html> <head> <title>Мой профиль</title> </head> <body> <p> Ваша репутация: <?php include 'bd.php'; $reputations = mysqli_query($db, "SELECT reputation FROM users WHERE login = '$login'"); $row = mysqli_fetch_assoc($reputations); echo $row['reputation']; ?> </p> </body> </html> 

No error, but does not output 0

Closed due to the fact that off-topic by the participants Kromster , Alexey Shimansky , Lex Hobbit , br3t , Eugene Krivenja August 28 '17 at 11:25 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, Alexey Shimansky, Lex Hobbit, br3t, Eugene Krivenja
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • add to the code under the query line to the database these rows $row = mysqli_fetch_assoc($reputations); echo $row['reputation']; $row = mysqli_fetch_assoc($reputations); echo $row['reputation']; - Edward
  • The same error occurs - Ytn
  • And if you do echo $ reputations; , then deduces nothing - Ytn
  • Add your code to the post with the question that you could see how and where you wrote it. - Edward
  • What code are you talking about? - Ytn

1 answer 1

 ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); 

I recommend adding this code before session_start(); to see errors. And add "quotes"

 SELECT `reputation` FROM `users` WHERE `login` = '$login' 

Slightly reworked code to see what's really going on.

 <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); session_start(); ?> <html> <head> <title>Мой профиль</title> </head> <body> <p> Ваша репутация: <?php include 'bd.php'; $reputations = mysqli_query($db, "SELECT `reputation` FROM `users` WHERE `login` = '$login'"); $row = mysqli_fetch_assoc($reputations); echo '<pre>'; print_r($row); echo '</pre>'; ?> </p> </body> </html> 

This code will display $row as an array. If it is still empty, you need to look for an error in the syntax or in the file 'bd.php'; .

 echo '<pre>'; print_r($row); echo '</pre>'; 

In general, I still recommend redoing under PDO .

 <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $pdo = new PDO("mysql:host=localhost;dbname=DBNAME;charset=utf8", 'root', 'PASSWORD'); $pr = $pdo->prepare("SELECT `reputation` FROM `users` WHERE `login` = :login"); $pr->execute(array( 'login' => $login )); $data = $pr->fetchAll(); echo '<pre>'; print_r($data); echo '</pre>'; 
  • I simply removed "WHERE login = '$ login'" and it all worked. I understand it because the session was open, but thanks for the help - Ytn