-2

When I run this code snippet :

<?php
$getposts = mysql_query("SELECT * FROM posts WHERE user_posted_to='$username' ORDER BY id DESC LIMIT 10") or die(mysql_error());

while ($row = mysql_fetch_assoc($getposts)) {
                        $id = $row['id'];
                        $body = $row['body'];   
                        $date_added = $row['date_added'];
                        $added_by = $row['added_by'];
                        $user_posted_to = $row['user_posted_to'];
                        $get_user_info = mysql_query("SELECT * FROM users WHERE username='$added_by'");
                                                $get_info = mysql_fetch_assoc($get_user_info);
                                                $profilepic_info = $get_info['profile_pic'];
                                                if ($profilepic_info == "") {
                                                 $profilepic_info = "./img/default_pic.jpg";
                                                }
                                                else
                                                {
                                                 $profilepic_info = "./userdata/profile_pics/".$profilepic_info;
                                                }
       echo "
                        <div style='float: left;'>
                        <img src='$profilepic_info' height='60'>
                        </div>
                        <div class='posted_by'>
                        Posted by:
                        <a href='$added_by'>$added_by</a> on $date_added</div>
                        <br /><br />$body<br /><br /><br /><br /><br />";
                        }
if (isset($_POST['sendmsg'])) {
 header("Location:send_msg.php?u=$username"); 
}

It outputs the following warning :

Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/socialnetwork/profile.php:27) in /opt/lampp/htdocs/socialnetwork/profile.php on line 30

Why does that code is not redirecting to msg_reply.php ? How to make this code work?

Vanu Aparna
  • 105
  • 8

1 Answers1

0

you can put ob_start(); at the top of the page without leaving any space. <?php ob_start();?>

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83