You call your header.php file by calling get_header()
function in single.php file. It means that your $postid_profile
variable exists only in scope of get_header()
function. To make it visible in global scope you need to make your variable global.
So your code should be modified like this:
### get the author info
global $current_user, $postid_profile;
get_currentuserinfo();
$authorid = $current_user->ID;
### get the last post id using author id
$info=mysql_query("SELECT * FROM wp_posts WHERE post_author = $authorid ORDER BY post_date DESC LIMIT 1");
$array_content = mysql_fetch_array( $info );
$postid_profile = $array_content['ID'];
Now your $postid_profile
variable will exist in global scope and will be accessible in single.php file.
As additional I would strongly recommend you to use $wpdb
variable to perform all db queries calls. Plus to get current user id you can use get_current_user_id()
function. So your code should be like this:
### get the author info
global $postid_profile;
get_currentuserinfo();
$authorid = get_current_user_id();
### get the last post id using author id
$array_content = $wpdb->get_row("SELECT * FROM wp_posts WHERE post_author = $authorid ORDER BY post_date DESC LIMIT 1", ARRAY_A);
$postid_profile = $array_content['ID'];