Message if PHP function successful or not!

Hello. I have this function where I am trying to add a new member to DB. I would like in my main code to display a message weather the function added the member to the DB or not. How can I do this?

Function:

public function addMemberToClass($m_id, $c_id)
		{
			$stmt = $this->link->prepare("SELECT * FROM classregistration WHERE classregistration.m_id = $m_id AND classregistration.c_id = $c_id  ");
			$stmt->execute();
			$stmt->store_result();
			$nRows = $stmt->num_rows;
			
			if ($nRows == 0)
			{ 
				$stmt2 = $this->link->prepare("INSERT INTO classregistration (m_id, c_id) VALUES (?, ?) ");
							$stmt2->bind_param("ii", $m_id, $c_id);
							$stmt2->execute();
							$stmt2->close();
					echo "Record added successfuly";
			}
			else{echo "Record not added as it exists already";} 
		}

Function Call:

$admin_query->addEmployerData($u_password, $u_name, $u_l_name, $u_DOB, $u_address, $u_email, $u_phone, $u_gender, $u_position, $u_contract_type, $u_contract_hours);

Thanks :smile:

->execute(); returns a boolean so you can simply wrap that execute function in an if statement and it’ll return true if it was successful.

Thanks :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.