Reputation: 5724
I have a small php class which i have edited a little to ask my question. The class is a shown beloww
class Register
{
public $notification = null;
public function __construct()
{
create_connection();
$this->validate_register();
}
public function validate_register()
{
//edit: missing double quote close
$select_register = "SELECT * FROM `student_reg`";
if($select_register_run = mysql_query($select_register))
{
$rows_returned = mysql_num_rows($select_register_run);
if($rows_returned >= 1)
{
$this->notification = 'error';
}else if($rows_returned == 0){
$this->notification = 'success';
}
}else{
$this->notification = 'error';
}
if($this->notification != null)
{
echo 'not null';
}else{ echo 'null';}
}
}
$new_register = new Register();
?>
It is clear that from the class, at any possible level, there is a value assigned to $this->notification
. But for some reason, the class 'echoes' null.
The creat_connection()
i built functions works perfectly but i have ommited it for the purpose of this question.
Why is this the case?
Upvotes: 0
Views: 64
Reputation: 1317
Try like this...
$select_register_run = mysql_query($select_register);
if($select_register_run){
//rest code
instead of
if($select_register_run = mysql_query($select_register))
Upvotes: 0
Reputation: 2009
Actually, if $rows_returned is less than 1 and not equal to 0, the code will echo 'null', so I suggest you echo $rows_returned.
Upvotes: 1