pr0cz pr0cz - 1 month ago 17
PHP Question

Insert a link into php crashes my site

I am faceing the problem, that my

$link
is not displayed. If I insert the lines described below, the site won't load anymore. The following code works properly.

<?php

$mysqli = new mysqli('host', 'name', 'psw', 'db');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = $mysqli->query("SELECT user_level FROM users WHERE user_level = 1 ")) {

/* determine number of rows result set */
$row_cnt = $result->num_rows;

printf("Result set has %d rows.\n", $row_cnt);
}

if ($result->num_rows == 1) {
printf ("Adminpanel");

$result->close();


}

/* close connection */
$mysqli->close();
?>


When I add this line

$link = 'AdminLayout.php';
printf ("<a href="' .$link. '">Adminpanel </a>");


instead of

printf ("Adminpanel");


nothing works anymore. What have I done wrong?

Answer

try this: its a quotes problem. if you need double quotes"" with href try with single quotes' at start and end.

$link = 'AdminLayout.php';
    printf ('<a href="' .$link. '">Adminpanel </a>');