[Solved] Why if…else stop working after I switched to DBO? [closed]


It is not whatever “DBO” but the code you wrote.
Although I managed to get it’s meaning only after reformatting it sanely.
Here it goes:

$select_links = "SELECT * FROM $table";
if (isset($_POST['link'])) {
    if ($_POST['link'] == '0'){
        // do nothing
    }
} else {
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

So, when you set POST link=1, it is passed isset($_POST['link']) check and then no other code being executed.

Most likely you meant something like this

if (!empty($_POST['link'])) {
    $select_links = "SELECT * FROM $table";
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

If you need some other logic – no problem, code whatever behaviour you want.
Just read the manual and test everything you try.
…but okay, this one could be hard for a newcomer:

if (!isset($_POST['link']) || $_POST['link']) {

means

IF $_POST['link'] is NOT set OR $_POST['link'] NOT equal to 0

0

solved Why if…else stop working after I switched to DBO? [closed]