CurrentValue returns null (v2023)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
elonmusk
User
Posts: 48

CurrentValue returns null (v2023)

Post by elonmusk »

rowRender()
{
      $slno = $this->SLNO->CurrentValue;
      executescalar("Select requster_name from emp_tbl where SLNO = $slno ");
}

For the above code i have getting "call to a member function on NULL" this error.
how to fix it ?
Thank you.


philmills
User
Posts: 555

Post by philmills »

try like this

{
$slno = $this->SLNO->CurrentValue;
ExecuteScalar("Select requster_name from emp_tbl where SLNO = '". $slno ."'");
}

arbei
User
Posts: 9384

Post by arbei »

The error meant $this->SLNO is null, you better check the field variable name. Also see Database, Table and Field Variable Names.


elonmusk
User
Posts: 48

Post by elonmusk »

When i trying

var_dump($slno);

returning NULL.

What could be the problem actually??


mobhar
User
Posts: 11727

Post by mobhar »

You should always check whether the field is not empty first:

if (!empty($this->SLNO->CurrentValue)) {
    $slno = $this->SLNO->CurrentValue;
    $val = ExecuteScalar("SELECT requster_name FROM emp_tbl WHERE SLNO = '". $slno ."'");
    // and so forth ...
}

arbei
User
Posts: 9384

Post by arbei »

arbei wrote:

The error meant $this->SLNO is null, you better check the field variable name.

If you use PHP 8.1, you better use "?->", e.g. if ($this->SLNO?->CurrentValue) { ... }.


Post Reply