-2

I've got a problem. I did the Code below (no Comments cause of the bad coding). In my DB there is one row with the id = 1 and the name = Ole. But when I write " echo "$result " ; " It says "Yannik". Don't know why pls help:D

 <?php 
   session_start();     
   require_once ("config.php");

   $Benutzer = $_SESSION['Name'] ;

   $sql = "SELECT bla From test WHERE id = 1 "; 

   $res= mysql_query($sql) or die (mysql_error());

   $result=$res['bla'];   

   echo "$result </br>" ;   
?>
skrilled
  • 5,350
  • 2
  • 26
  • 48
  • 3
    This means that name is `Yannik` or you don't show us full code. – u_mulder May 05 '16 at 19:12
  • 4
    You aren't selecting `name`, you are selecting `bla`. – chris85 May 05 '16 at 19:17
  • COde doesn't fit the description; and we have no idea what's in your database... Please help us help you! – Webomatik May 05 '16 at 19:43
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 05 '16 at 19:48

2 Answers2

1

try this

while ($row = mysql_fetch_assoc($res)) {
    echo $row["bla"];
}

http://php.net/manual/en/function.mysql-fetch-assoc.php

ElijahJoel
  • 11
  • 2
0

you hadnot converted the $res to an array. Use $result=mysqli_fetch_assoc($res);

jophab
  • 5,356
  • 14
  • 41
  • 60