Question : php reply always the same

This code allows gives me the same return_msg=no_good.
I think it has to do with sessions and $username, does anyone know how I can fix this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
<?php
session_start();

if(!isset($_SESSION['username'])){
    echo "Error";
	}else{
	$username = $_SESSION['username']; 

}

///////  Mechanism to determine if the user has and data saved to this table  //////////////////////////
	include_once "connect_to_mysql.php";
	
	$sql = mysql_query("SELECT * FROM portfolio WHERE username='$username'");
	$username_check=mysql_num_rows($sql);

		echo "username=$username";
  if ($username = 0){
	while($row = mysql_fetch_array($sql)){

 			print "return_msg=all_good";
			  }
	} else {
	    	print "return_msg=no_good"; 
 		exit();   
    } // close while
?>

Answer : php reply always the same

ah, probably because the last fetch array gives False.   If I understand this right, you want it to print "good" if there is any row for this username,  and no good only if there is no row.

If that is correct, then try this:

///////  Mechanism to determine if the user has and data saved to this table  //////////////////////////  
include_once "connect_to_mysql.php";  
 
$sql = mysql_query("SELECT * FROM portfolio WHERE username='$username'");  
if ( mysql_num_rows($sql) == 0)
  print "return_msg=no_good";    
else
  print "return_msg=all_good";


Random Solutions  
 
programming4us programming4us