Error in IF condition

1

I'm doing a program in PHP but I'm having a problem. I want it, when $ user_info is equal to Tiago Goncalves, show the user image. The truth is that it is shown on the website all 3 pictures.
HTML

<html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>TI-Trash | Gestão de Resíduos</title>
        <link rel="stylesheet" href="/css/main.css">
    </head>

    <body>
        <h1 style="text-align: center">---------------------------------------------------------TI-Trash----------------------------------------------------------</h1>
        <img src="img/logo/White%20with%20Colorful%20Icon%20Computer%20Logo%20(1).png" style="width:200px;height:200px;" align="right"><br>

        <h1 style="text-align:left">Introduza o seu ID</h1>

        <form action="results.php" method="post">
            <label for="user_id">ID:</label><br>
            <input type="text" id="user_id" name="user_id"><br>
            <input type="submit">
        </form>
        <br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        <p style="text-align: center">Aplicação WEB produzida por<br style="text-align:center">Tiago Gonçalves</p>
            <p style="text-align:center">com ajuda de<br><br>Tiago Cardoso</p>
    </body>
</html>

PHP

<?php
                if( $user_info ){
                    if( $user_info['nome'] = 'Tiago Gonçalves'){
                        echo '<img src="img/users/Tiago.jpg">';
                    }
                    if( $user_info['nome'] = 'Alexandre Salgado'){
                        echo '<img src="img/users/Alexandre.jpg">';
                    }
                    if( $user_info['nome'] = 'Ricardo Cardoso'){
                        echo '<img src="img/users/Ricardo.jpg">';
                    }

                    echo '<h1> ' . $user_info['nome'] . '</h1>' ;
                    echo '<p> ' . $user_info['email'] . '</p>';
                    echo '<table style="border: 1px solid black;">';
                    echo '<tr>';
                        echo '<th>Quantidade   </th>';
                        echo '<th>Localização de Depósito   </th>';
                        echo '<th>Data/Hora de Depósito</th>';
                    echo '</tr>';

                    $total = 0.0 ;
                    foreach( $user_dumps as $dump ){
                        $total += $dump['quantity'];
                        echo '<tr>';
                            echo '<td align="center">' . $dump['quantity'] . '</td>';
                            echo '<td align="center">' . $containers[$dump['container_id']] . '</td>';
                            echo '<td align="center">' . $dump['timestamp'] . '</td>';
                        echo '</tr>';
                    }
                    echo '</table><br>';


                    echo '<h3 style="color: red;"> Total de Resíduos Registados: ' . $total . 'kg</h3>';

                    //O valor a pagar é 10% do peso dos resíduos registados
                    echo '<h3 style="color: red;"> A pagar: ' .$total*0.10 . '€</h3>';
                }
            else{
                    echo '<h1>Nenhum utilizador com o ID introduzido atribuido!</h1>';
                }

                    echo '<form action="index.php"><input type="submit" value="IDs" /></form>';
            ?>

Database

BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS 'users' (
    'id'    INTEGER,
    'nome'  TEXT NOT NULL,
    'telemovel' INTEGER,
    'nif'   INTEGER NOT NULL,
    'email' TEXT
);
INSERT INTO 'users' VALUES (1,'Tiago Gonçalves
',968074232,263071030,'[email protected]');
INSERT INTO 'users' VALUES (2,'Alexandre Salgado',393564525,152635968,'[email protected]');
INSERT INTO 'users' VALUES (3,'Ricardo Cardoso',895475454,265365365,'[email protected]');
CREATE TABLE IF NOT EXISTS 'garbage' (
    'user_id'   INTEGER,
    'container_id'  INTEGER,
    'quantity'  REAL,
    'timestamp' NUMERIC,
    PRIMARY KEY('user_id','container_id','quantity','timestamp')
);
INSERT INTO 'garbage' VALUES (1,1,1.23,20180801192202);
INSERT INTO 'garbage' VALUES (1,1,56.9,20180801103555);
INSERT INTO 'garbage' VALUES (1,1,12.0,20180730135533);
INSERT INTO 'garbage' VALUES (3,2,152.0,20180801192202);
CREATE TABLE IF NOT EXISTS 'containers' (
    'id'    INTEGER PRIMARY KEY AUTOINCREMENT,
    'location'  TEXT
);
INSERT INTO 'containers' VALUES (1,'R. Dr. Lino Cardoso 66, 3060-209 Cantanhede');
INSERT INTO 'containers' VALUES (2,'Rua Camarao
');
INSERT INTO 'containers' VALUES (3,NULL);
COMMIT;

What should I do so that when I enter, for example, user_id 1, show the image corresponding to the user James?

    
asked by anonymous 02.08.2018 / 19:55

1 answer

4

Note that you are not using the comparer but rather assigning the value to the variable:

if( $user_info['nome'] = 'Tiago Gonçalves')

The correct one would be:

if( $user_info['nome'] == 'Tiago Gonçalves')

Correcting the code:

if( $user_info['nome'] == 'Tiago Gonçalves'){
   echo "<img src='img/users/Tiago.jpg'>";
}
else if( $user_info['nome'] == 'Alexandre Salgado'){
   echo "<img src='img/users/Alexandre.jpg'>";
}
else if( $user_info['nome'] == 'Ricardo Cardoso'){
   echo "<img src='img/users/Ricardo.jpg'>";
}
    
02.08.2018 / 19:57