error converting mysqli to pdo

hello i tried to switch from mysqli to pdo but somehow i made a mistake

MYSQLI
  $qry = "SELECT * FROM con where id= '$user'";  
                                    $result = mysqli_query($conn, $qry);
                                    while ($row = mysqli_fetch_assoc($result)) {
                        
                                    print_r($row["convoy_cars"], true);
                                    if($row["convoy_cars"] == 1){
                                    echo '<div class="dashtext-3">Autos f&uuml;r Spieler erlaubt:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></div></i> </a>';
                                    
                                    }
                                    elseif($row["convoy_cars"] == 2){
                                    echo '<div class="dashtext-3">Autos f&uuml;r Spieler erlaubt:   <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                  
                                    }
                                    print_r($row["convoy_hct"], true);
                                    if($row["convoy_hct"] == 1){
                                    echo '<div class="dashtext-3">HCT-Trailer erlaubt:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>';
                                    
                                    }
                                    elseif($row["convoy_hct"] == 2){
                                    echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                    print_r($row["convoy_absicherung"], true);
                                    }
                                    if($row["convoy_absicherung"] == 1){
                                    echo '<div class="dashtext-3">Absicherung:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>';
                                    
                                    }
                                    elseif($row["convoy_absicherung"] == 2){
                                    echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                  
                                    
                                    }
                                   }
my try in pdo
 $qry = "SELECT * FROM con where id= '$user'";  
                                    $result = $pdo->prepare($qry);
                                    while ($row = $qry->fetch(PDO::FETCH_ASSOC)){
                        
                                    print_r($row["convoy_cars"], true);
                                    if($row["convoy_cars"] == 1){
                                    echo '<div class="dashtext-3">Autos f&uuml;r Spieler erlaubt:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></div></i> </a>';
                                    
                                    }
                                    elseif($row["convoy_cars"] == 2){
                                    echo '<div class="dashtext-3">Autos f&uuml;r Spieler erlaubt:   <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                  
                                    }
                                    print_r($row["convoy_hct"], true);
                                    if($row["convoy_hct"] == 1){
                                    echo '<div class="dashtext-3">HCT-Trailer erlaubt:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>';
                                    
                                    }
                                    elseif($row["convoy_hct"] == 2){
                                    echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                    print_r($row["convoy_absicherung"], true);
                                    }
                                    if($row["convoy_absicherung"] == 1){
                                    echo '<div class="dashtext-3">Absicherung:   <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>';
                                    
                                    }
                                    elseif($row["convoy_absicherung"] == 2){
                                    echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>';
                                  
                                    
                                    }
                                   }

Well, if you PREPARE a query, you do NOT put the data in the query. You do this after you EXEC the query.
Loosely, $pdo->prepare(“SELECT * FROM con WHERE id=?”);
Then, again, loosely, $pdo->exec($user);
This protects your database.

I think you should read this page. It is very long and covers just about all PDO you will ever need.
https://phpdelusions.net/pdo Hope this helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service