0

Right now I'm coding this really simple user page but getting one problem that's bugging me and can't find out why it's happening.

When ever I would put <?php HTML will just stop loading from there.

<?php

session_start();

if (!isset($_SESSION["user"])) {

    $logged_in = "no";

} else {

    $username = $_SESSION["user"];
    $logged_in = "yes";

}

include ('global.php');

?>

<head>

    <title><?php echo $sitename; ?></title>
    <link rel="stylesheet" type="text/css" href="css.css">
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

    <div class="header">

        <div class="header_content">

            <div class="middle_logo">

                <p><a href="index.php"><?php echo $sitename; ?></a></p>

            </div>

        </div>

    </div>

    <div class="under_header">

        <?php

                $id = htmlentites($_GET["id"]);

                $get_user_data = mysqli_query ($dconnect, "SELECT * FROM user_data WHERE id='$id'");

                if (mysqli_num_rows($get_user_data) < 2) {

                    header ("Location: index.php");

                } else {

                while ($row = mysqli_fetch_array($get_user_data)) {

                    echo $row["username"];

               }

                }

        ?>

        <h1><?php echo $users_name; ?></h1>

    </div>

When I look at the source code it ends at <div class="under_header">

  • 4
    Use this `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);` to check error on page – Saty Apr 06 '17 at 12:26
  • There's an error in your PHP code. – Morgs Apr 06 '17 at 12:31
  • 2
    Function `htmlentites()` does not exist. However function `htmlentities()` does. Correct that and it will stop the PHP **Crashing** In future ... Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Apr 06 '17 at 12:31
  • 1
    `htmlentities` is not equal to `htmlentites`, first one is right, better use an tool like phpstrom for developing. If `$_GET["id"]` is alwys a integer do just `$id = (int)$_GET["id"];` currently you are open for SQLInjections – JustOnUnderMillions Apr 06 '17 at 12:32
  • Thanks everyone, haven't seen that I wrote htmlentites .. btw thanks again, – Marjan Simic Apr 06 '17 at 12:57

1 Answers1

0

The answer has already been found in the comment :

The line :

 $id = htmlentites($_GET["id"]);

Contain an error and should be :

 $id = htmlentities($_GET["id"]);

Thanks to @RiggsFolly and @JustOnUnderMillions. You can now accept an answer and close the question.

Nirnae
  • 1,315
  • 11
  • 23