I have a problem in my following code. THis code show a massege.Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\bangla_music_store\music-admin\login.php:12) in C:\xampp\htdocs\bangla_music_store\music-admin\login.php on line 40 Please solve this. <?php session_start(); ?> <html> <head> <title>.::Log In::.</title> </head> <body> <?php include_once('menubar.php'); add_header(); //admin_menu(); include_once ("config/common_db.inc"); $link_id=db_connect(); $uname=$_POST['username']; $password=$_POST['pass']; $query="SELECT * FROM music_admin WHERE user_name='$uname' AND admin_password ='$password'"; $result=mysql_query($query); $row=mysql_fetch_array($result); //Find Access Level $user_name=$row[2]; $pass=$row[3]; $access_level=$row[5]; $usr_id=$row[0]; if(mysql_num_rows($result)>0) { //Redirect User As Access Level switch($access_level) { case "1": header("Location:.php"); break; case "2": header('Location: add_admin.php'); break; case "3": header("Location: .php"); break; default: echo "No number between 1 and 3"; } //header('location:add_admin.php'); } else { echo "<br>"; echo "<br>"; echo "<br>"; echo "<div align=\"center\">"; echo "<h3>Your Username or Password is Wrong! You Will Redirect To The Log In Page </h3>"; header('Location: index.php'); echo "<h3>If Your Brower Doesn't Suport It, Please Log In<a href=\"index.php\">Here</a></h3>"; echo "</div>"; } ?> </body> </html>
If you wish to redirect user via header you should do it before anything is sent to browser. In your script html tags are sent before headers, that's why you get this message.
add this before everything: <?php ob_start(); ?> PHP: and this after everything: <?php ob_flush(); ?> PHP: