I want to make a certain twig input form on a web page available to user if he have a certain value in her database $row['GameId'];
so I tried to write if statement for the code like that
$sqlo = $conn->query("SELECT * FROM user WHERE username='$tuser'");
while ($row = $sqlo->fetch(PDO::FETCH_ASSOC))
{
$gid = $row['GameId'];
if($gid == 0 ){
$investor = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy(array('id' => $user->getId()));
$MatchP = $investor->getMatchP();
$form = $this->createForm(new TaskType(), $investor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if(!empty($form->get('MatchP')->getData())){
$investor->setMatchP($form->get('MatchP')->getData());
}
else{
$investor->setMatchP($MatchP);
}
$em = $this->getDoctrine()->getManager();
$em->persist($investor);
$em->flush();
$session = $this->getRequest()->getSession();
/**
* @Route("/siteblog_homepage/")
*/
return $this->redirectToRoute('siteblog_homepage');
}
}
else{
?> your value are not the right one to access to this page <?
}
return $this->render('siteblogBundle:Default:index.html.twig', array(
'form' => $form->createView(),
));
//}
}
but i get this error
Notice: Undefined variable: form
because this line
'form' => $form->createView(),
so how to protect this page on the wright way ?