title: Why is PHP giving off a undefined variable message for this code?
body: <p>I have this code. It's just for testing purposes, so you don't need to tell me to use parameter binding and prepared statements and PDO to avoid SQL Injection. </p>
  
  <pre><code>foreach($dd-&gt;getElementsByTagName("ReportItem") as $elmt){
      foreach ($elmt-&gt;childNodes as $node){
          if($node-&gt;nodeName==="ModuleName")
              $name = $node-&gt;nodeValue;
  
              if($result=mysqli_query($conn,"select * from technology_info where name = $name")){
                  if(mysqli_num_rows($result)==0){
  
                      mysqli_query($conn,"insert into technology_info(id,name,tool_id) values(null,$name,'2')");
                      //ERROR: Undefined variable: name 
  
                  }
  
              }
          }
  }
  </code></pre>
  
  <p>This is what the code is meant to accomplish: if variable <code>$name</code> is a value that is already in the database, do nothing. Otherwise, add it to the database.</p>
  
  <p>However, I'm getting an error message: <strong>Notice: Undefined variable: name in /var/www/teste/index5.php</strong></p>
  
  <p>I mean, the variable <strong>is</strong> there. Any idea what might be happening?</p>