Skip to content
Advertisement

html after include_once doesn’t exist

I’m making a users table and I’m including a part of the table(the users) with a php page that I call with include_once.

after that include my html doesn’t exist when I run the page(with localhost). the code isn’t hidden, it simply doesn’t exist.

this is my table and include function:

<form onsubmit="return confirm('are you sure that you want to delete this user?');" action="includes/delete_user-inc.php" method="post">

                    <div>
                        <h2>All purchesed products:</h2>
                    </div>
                                <div>
                                <table class="pt">
                                    <tr> <th class="t">Id</th>
                                        <th class="t">Userame</th>
                                        <th class="t">Email</th>
                                        <th class="t">delete</th>
                                    </tr>
                                    <?php 
                                        include_once 'includes/manage_users-inc.php';
                                        ?>
                                </table>                       
                                </div>  
                                    </form>   

any html after this point doesn’t show in the file

the php code:

<?php 

require 'dbh-inc.php';

$id = $_SESSION['userId'];
 if(!isset($id))
    {
        header("Location:../login.php");
        exit();

    }
$num=-1;

                    $sql = "SELECT idUsers, uidUsers, emailUsers FROM users;";
                    $result = mysqli_query($conn, $sql);
                    if($result->num_rows > 0){
                    while($row = mysqli_fetch_assoc($result)){
                        $num = $num +1;

                      echo  "<tr><td>".$row['idUsers'].
                          "</td><td>". $row['uidUsers'].
                          "</td><td>". $row['emailUsers'].
                          "</td><td><input type="submit" name="submit[" . $row['idUsers'] . "]" value="delete user" class="button"></td></tr>" ;
                    }    
                    } 
exit();
?>

what do I need to do to fix the html disappearing? thanks!

Update: I was wrongly mistaken that every php script has to have an exit() function. while including a script, using the exit() function will exit the parent page and only the including page. include injects code into another page, it doesn’t “call” another page.

Advertisement

Answer

Get rid of the

exit();

line in the include file, because it’s causing the main script to exit before printing the rest of the HTML.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement