0

My query is as follow:

function AfterSuccessfulRegistration($userdata, $pageObject)
{
$tmp_UserName = $userdata["login"];
$tmp_GroupID = $userdata["groupid"];

$rs = DB::Query("SELECT  `UserName`, `GroupID` FROM users_ugmembers where `UserName` = `$tmp_UserName`");
$data = $rs->fetchAssoc();
if($data)
{
  // if record exists do something
}
else
{
  DB::Exec("insert into users_ugmembers (`UserName`, `GroupID`) values (`$tmp_UserName` , `$tmp_GroupID)`");
}
} // function AfterSuccessfulRegistratio

n

How can I correct the error: Fatal error: Call to a member function fetchAssoc() on a non-object

  • 1
    Does this answer your question? [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – El_Vanja Feb 17 '21 at 16:00
  • The username in the query (which you should use prepared statements anyway) should be in normal quotes (either single or double) and not backticks (`\`$tmp_UserName\``) – Nigel Ren Feb 17 '21 at 16:00

0 Answers0