-2

The PHP code enlarges my navbar.

When I remove the PHP part, my web page's navbar becomes normal (same as my other web pages' navbars which don't have any PHP code). But when the PHP code is present, the navbar becomes enlarged.

<?php
include "connection.php";
$roll_no=$_REQUEST["rollno"];
session_start();
$_SESSION['rollno'] = $roll_no;
$fetch=mysqli_query($connection,"select * from std_detail where std_rollno='$roll_no' ");

while($res=mysqli_fetch_assoc($fetch)){?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" href="CSS.css">
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
  <div class="navbar-header">
    <a href="Receipt.php" class="navbar-brand"><span class="glyphicon glyphicon-picture" aria-hidden="true"></span> IMAGE</a>
  </div>
  <div class="collapse navbar-collapse" id="bs-nav-demo">
      <ul class="nav navbar-nav">
          <li><a href="Register.php">Register</a></li>
          <li><a href="Search.php"><h3 style="display: inline;" class="fas fa-search"></h3></a></li>
      </ul>
    <ul class="nav navbar-nav navbar-right">
        <li><a href="AdminLogin.php">Login Page <i class="fas fa-user"></i></a></li>
    </ul>
  </div>
</div>
</nav>
</body>
</html>
<?php }  ?>

Expected: normal navbar Actual: enlarged navbar

  • 1
    You are outputting your *entire* web page on every iteration of your loop – John Conde Apr 18 '19 at 23:13
  • 1
    Please read about **[SQL injection](https://en.wikipedia.org/wiki/SQL_injection)**. Instead of building queries with string concatenation, use **[prepared statements](https://secure.php.net/manual/en/pdo.prepare.php)** with **[bound parameters](https://secure.php.net/manual/en/pdostatement.bindparam.php)**. See **[this page](https://phptherightway.com/#databases)** and **[this post](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)** for some good examples. – John Conde Apr 18 '19 at 23:14

1 Answers1

-2

The problem probably is, the php is outputing text. Add ob_start() and ob_end_clean()

<?php
@ob_start();
include "connection.php";
$roll_no=$_REQUEST["rollno"];
session_start();
$_SESSION['rollno'] = $roll_no;
$fetch=mysqli_query($connection,"select * from std_detail where std_rollno='$roll_no' ");

while($res=mysqli_fetch_assoc($fetch)){
@ob_end_clean();
?>

check also the suggestio from John Conde about the SQL Injection, prepared statements, etc

Alex Angelico
  • 3,710
  • 8
  • 31
  • 49
  • Thanks for your help. But the main problem was in connection.php. There were some links for CSS files, i deleted them and it works now. – Amit Raj Singh Apr 19 '19 at 14:37