title: PHP $_POST[key] return value
body: <p>I came across a PHP question paper which provided a code sample associated with the functionality of a product cart. When I went through the code sample, I came across certain PHP if conditions which checks, if a variable to which a $_POST[key] value was assigned, is false. The following are the code samples associated with problem I am facing.</p>
  
  <p>nicepage.php</p>
  
  <pre><code>$id=$_GET['previd'];
  $SQL = "select * from pro where prId=".$id;
  $runSQL = mysql_query($SQL) or die(mysql_error());
  $details = mysql_fetch_array($runSQL);
  echo "&lt;p&gt;Catalogue Item Number: ".$details['prId'];
  echo "&lt;p&gt;". strtoupper($details['prName']);
  echo "&lt;p&gt;".$details['prDescrip'];
  echo "&lt;p&gt;&lt;img src=images/".$details['prPicName']."&gt;";
  echo "&lt;p&gt;£".$details['prPrice'];
  echo "&lt;p&gt;".$details['prQuantity']." items for you to get!" ;
  echo "&lt;form method=post action=greatpage.php&gt;" ;
  echo "&lt;p&gt;Enter how many: ";
  echo "&lt;input type=text name=newqu size=5 maxlength=3&gt;";
  echo "&lt;input type=submit value='Get them'&gt;";
  echo "&lt;input type=hidden name=newid value=".$id."&gt;";
  echo "&lt;/form&gt;" ;
  echo "&lt;/center&gt;";
  echo "&lt;/body&gt;";
  echo "&lt;/html&gt;";
  </code></pre>
  
  <p>greatpage.php</p>
  
  <pre><code>$theid=$_POST['newid'];
  $thequ=$_POST['newqu'];
  if (!$theid)
  {
  echo "&lt;p&gt;Nothing new is added, show the stuff from before";
  }
  else
  {
  if (!$thequ or $thequ==0)
  {
  echo "&lt;p&gt;Error!";
  echo "&lt;p&gt;&lt;a href=nicepage.php&gt;Enter correct value!&lt;/a&gt;";
  exit;
  }
  else
  {
  $theSQL="select prQuantity from pro where prId=".$theid;
  $runtheSQL=mysql_query($theSQL) or die (mysql_error());
  $info=mySQL_fetch_array($runtheSQL);
  $ourqu=$info['prQuantity'];
  if ($thequ &gt; $ourqu)
  {
  echo "&lt;p&gt;Not good!";
  echo "&lt;p&gt;&lt;a href=nicepage.php&gt; Do it again!&lt;/a&gt;";
  exit;
  }
  else
  {
  echo "&lt;p&gt;Great, item added!";
  $_SESSION['storage'][$theid]=$thequ;
  }
  }
  }
  </code></pre>
  
  <p>The above code samples provide parts of the PHP scripts associated with the issue.</p>
  
  <p>I am a relatively new PHP programmer, hence pardon me for any mistakes, I make. </p>
  
  <p>I would like to learn why the <code>$theid</code> and <code>$thequ</code> are checked if they are equal to false rather than using a function like <code>isset($_POST['key'])</code> to check if <code>$_POST</code> global variables are set before assigning to the two PHP <code>$theid</code> and <code>$thequ</code> variables.</p>
  
  <p>And in the above code sample, which situations may lead to the <code>!$theid</code> and <code>!$thequ</code> being true?</p>
  
  <p>I would be extremely grateful to anyone who can solve this conundrum.</p>