0

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?

7
  • 1
    Missing quote " at the end of this line ? $select_register = "SELECT * FROM student_reg; Commented Mar 14, 2014 at 13:25
  • 1
    Seems like the script can't get past this line: if($select_register_run = mysql_query($select_register)) Do you have error_reporting(E_ALL); on? Commented Mar 14, 2014 at 13:27
  • That was an error while retyping the code here.. the mysql is okay Commented Mar 14, 2014 at 13:30
  • What's the value on $rows_returned? Maybe it's returning a non-numerical value? Commented Mar 14, 2014 at 13:31
  • You don't keep the mysql connection anywhere in the class context. Missing something like $this->databaseConnection = create_connection(); You really should use PDO or Mysqli Commented Mar 14, 2014 at 13:32

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.