How do I not generate error when not receiving a variable in PHP? [closed]

-1

INDEX.PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="css/estilo.css" rel="stylesheet">
<?php include'cardapio.php';?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body bgcolor="#000";>
<span class="h">
<center>
<form method="post" action="pedido.php">

 <br>
  &nbsp; <?php echo $sashimi['sashimi']['titulo'];?> <br>  <input type="checkbox" name="sashimi11" value="SASHIMI SALMÃO" align="middle">  
  &nbsp; <?php echo $sashimi['sashimi11']['id'];?> 
  &nbsp; <?php echo $sashimi['sashimi11']['tipo'];?> 
  &nbsp; <?php echo $sashimi['sashimi11']['quantidade'];?>
  &nbsp; <?php echo $sashimi['sashimi11']['preco'];?> 
  <input type="number" name="qt_sashimi11" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" /> 

 <br>
 <br />
  &nbsp; <?php echo $hot ['hot']['titulo'];?> <br> 
  <input type="checkbox" name="hot21" value="HOT FILADÉLFIA" align="middle">  
  &nbsp; <?php echo $hot ['hot21']['id'];?> 
  &nbsp; <?php echo $hot ['hot21']['tipo'];?> 
  &nbsp; <?php echo $hot ['hot21']['quantidade'];?>
  &nbsp; <?php echo $hot ['hot21']['preco'];?> 
  <input type="number" name="qt_hot21" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
<br>
  <input type="hidden" name="hot22" value="Romeu e Julieta" />
  &nbsp; <?php echo $hot ['hot22']['id'];?> 
  &nbsp; <?php echo $hot ['hot22']['tipo'];?> 
  &nbsp; <?php echo $hot ['hot22']['quantidade'];?>
  &nbsp; <?php echo $hot ['hot22']['preco'];?> 
  <input type="number" name="qt_hot22" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br>
 <br>
  &nbsp; <?php echo $uramaki['uramaki']['titulo'];?> <br>   
  <input type="hidden" name="uramaki31" value="Filadélfia" />
  &nbsp; <?php echo $uramaki['uramaki31']['id'];?> 
  &nbsp; <?php echo $uramaki['uramaki31']['tipo'];?> 
  &nbsp; <?php echo $uramaki['uramaki31']['quantidade'];?>
  &nbsp; <?php echo $uramaki['uramaki31']['preco'];?> 
  <input type="number" name="qt_uramaki31" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
 <br>
   <input type="hidden" name="uramaki32" value="Califórnia" />
  &nbsp; <?php echo $uramaki['uramaki32']['id'];?> 
  &nbsp; <?php echo $uramaki['uramaki32']['tipo'];?> 
  &nbsp; <?php echo $uramaki['uramaki32']['quantidade'];?>
  &nbsp; <?php echo $uramaki['uramaki32']['preco'];?> 
  <input type="number" name="qt_uramaki32" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
 <br>
   <input type="hidden" name="uramaki33" value="Romeu e Julieta" />
  &nbsp; <?php echo $uramaki['uramaki33']['id'];?> 
  &nbsp; <?php echo $uramaki['uramaki33']['tipo'];?> 
  &nbsp; <?php echo $uramaki['uramaki33']['quantidade'];?>
  &nbsp; <?php echo $uramaki['uramaki33']['preco'];?> 
  <input type="number" name="qt_uramaki33" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
 <br>

   <input type="hidden" name="uramaki34" value="Skin" />
  &nbsp; <?php echo $uramaki['uramaki34']['id'];?> 
  &nbsp; <?php echo $uramaki['uramaki34']['tipo'];?> 
  &nbsp; <?php echo $uramaki['uramaki34']['quantidade'];?>
  &nbsp; <?php echo $uramaki['uramaki34']['preco'];?> 
  <input type="number" name="qt_uramaki34" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
 <br>
  <br>
  &nbsp; <?php echo $hossomaki['hossomaki']['titulo'];?> <br>   
  <input type="hidden" name="hossomaki41" value="Filadélfia" />
  &nbsp; <?php echo $hossomaki['hossomaki41']['id'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki41']['tipo'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki41']['quantidade'];?>
  &nbsp; <?php echo $hossomaki['hossomaki41']['preco'];?> 
  <input type="number" name="qt_hossomaki41" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br />
  <input type="hidden" name="hossomaki42" value="Filadélfia" />
  &nbsp; <?php echo $hossomaki['hossomaki42']['id'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki42']['tipo'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki42']['quantidade'];?>
  &nbsp; <?php echo $hossomaki['hossomaki42']['preco'];?> 
  <input type="number" name="qt_hossomaki42" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br />
  <input type="hidden" name="hossomaki43" value="Filadélfia" />
  &nbsp; <?php echo $hossomaki['hossomaki43']['id'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki43']['tipo'];?> 
  &nbsp; <?php echo $hossomaki['hossomaki43']['quantidade'];?>
  &nbsp; <?php echo $hossomaki['hossomaki43']['preco'];?> 
  <input type="number" name="qt_hossomaki43" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br />
<br>
  &nbsp; <?php echo $niguiri['niguiri']['titulo'];?> <br>   
  <input type="hidden" name="niguiri51" value="Filadélfia" />
  &nbsp; <?php echo $niguiri['niguiri51']['id'];?> 
  &nbsp; <?php echo $niguiri['niguiri51']['tipo'];?> 
  &nbsp; <?php echo $niguiri['niguiri51']['quantidade'];?>
  &nbsp; <?php echo $niguiri['niguiri51']['preco'];?> 
  <input type="number" name="qt_niguiri51" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br />
  <input type="hidden" name="niguiri52" value="Filadélfia" />
  &nbsp; <?php echo $niguiri['niguiri52']['id'];?> 
  &nbsp; <?php echo $niguiri['niguiri52']['tipo'];?> 
  &nbsp; <?php echo $niguiri['niguiri52']['quantidade'];?>
  &nbsp; <?php echo $niguiri['niguiri52']['preco'];?> 
  <input type="number" name="qt_niguiri52" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
<br />
   <input type="hidden" name="niguiri53" value="Filadélfia" />
  &nbsp; <?php echo $niguiri['niguiri53']['id'];?> 
  &nbsp; <?php echo $niguiri['niguiri53']['tipo'];?> 
  &nbsp; <?php echo $niguiri['niguiri53']['quantidade'];?>
  &nbsp; <?php echo $niguiri['niguiri53']['preco'];?> 
  <input type="number" name="qt_niguiri53" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
<br />
<br>
  &nbsp; <?php echo $temaki['temaki']['titulo'];?> <br>   
  <input type="hidden" name="temaki61" value="Salmão" />
  &nbsp; <?php echo $temaki['temaki61']['id'];?> 
  &nbsp; <?php echo $temaki['temaki61']['tipo'];?> 
  &nbsp; <?php echo $temaki['temaki61']['quantidade'];?>
  &nbsp; <?php echo $temaki['temaki61']['preco'];?> 
 <input type="number" name="qt_temaki61" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
<br />
  <input type="hidden" name="temaki62" value="Filadélfia" />
  &nbsp; <?php echo $temaki['temaki62']['id'];?> 
  &nbsp; <?php echo $temaki['temaki62']['tipo'];?> 
  &nbsp; <?php echo $temaki['temaki62']['quantidade'];?>
  &nbsp; <?php echo $temaki['temaki62']['preco'];?> 
 <input type="number" name="qt_temaki62" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;" />
<br />
  <input type="hidden" name="temaki63" value="Califórnia" />
  &nbsp; <?php echo $temaki['temaki63']['id'];?> 
  &nbsp; <?php echo $temaki['temaki63']['tipo'];?> 
  &nbsp; <?php echo $temaki['temaki63']['quantidade'];?>
  &nbsp; <?php echo $temaki['temaki63']['preco'];?> 
 <input type="number" name="qt_temaki63" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
<br />
  <input type="hidden" name="temaki64" value="Romeu e Julieta" />
  &nbsp; <?php echo $temaki['temaki64']['id'];?> 
  &nbsp; <?php echo $temaki['temaki64']['tipo'];?> 
  &nbsp; <?php echo $temaki['temaki64']['quantidade'];?>
  &nbsp; <?php echo $temaki['temaki64']['preco'];?> 
 <input type="number" name="qt_temaki64" min="0" max="10"  placeholder="0" style="border-radius:5px 5px 5px 5px; text-align:center; size:1;"/>
 <br />
<br />
<br />
<input type="submit" value="PASSO 2" style="border-radius:5px 5px 5px 5px; text-align:center; width:100px; height:30px; font-size:18px;" />
  </form>
</center>
</span>
</body>
</html>

ORDER.PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/estilo.css">
<?php
/*SASHIMI*/
$qt_sashimi11 = isset($_POST['qt_sashimi11'])? $_POST['qt_sashimi11'] : null; 
if($qt_sashimi11 == null) die("");

$sashimi11 = isset($_POST['sashimi11'])? $_POST['sashimi11'] : null; 
if($sashimi11 == null) die("");

/*HOT FILADELFIA*/
$qt_hot21 = isset($_POST['qt_hot21'])? $_POST['qt_hot21'] : null; 
if($qt_hot21 == null) die("");

$hot21 = isset($_POST['hot21'])? $_POST['hot21'] : null;
if($hot21 == null) die("");
?>


<input type="hidden" name="qt_sashimi11" value="<?php echo $qt_sashimi11; ?>" />
<input type="hidden" name="sashimi11" value="<?php echo $sashimi11; ?>" />
<?php echo $qt_sashimi11 ;?> &nbsp;<?php echo $sashimi11 ;?> 
<br />
<input type="hidden" name="qt_hot21" value="<?php echo $qt_hot21; ?>" />
<input type="hidden" name="hot21" value="<?php echo $hot21; ?>" />
<?php echo $qt_hot21 ;?> &nbsp;<?php echo $hot21 ;?>
</head>
<body>

<form method="post" action="">
<input type="hidden" name="$sashimi11" />


<input type="submit" value="PASSO 3">
</form>


</body>
</html>
    
asked by anonymous 05.11.2014 / 22:20

1 answer

2

Something faster, no need to stick with if's

if (!isset($_POST['qt_sashimi11'])){
$qt_sashimi11 = NULL;
}

In short, if POST is not set, assign NULL to the variable. The !isset is equal to "not set"

While isset is equal to "set"

Another situation: If you assign POST to variable

if (!isset($_POST['qt_sashimi11'])){
$qt_sashimi11 = NULL;
} else {
$qt_sashimi11 = $_POST['qt_sashimi11'];
}
    
05.11.2014 / 22:47