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.
foreach($dd->getElementsByTagName("ReportItem") as $elmt){
foreach ($elmt->childNodes as $node){
if($node->nodeName==="ModuleName")
$name = $node->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
}
}
}
}
This is what the code is meant to accomplish: if variable $name is a value that is already in the database, do nothing. Otherwise, add it to the database.
However, I'm getting an error message: Notice: Undefined variable: name in /var/www/teste/index5.php
I mean, the variable is there. Any idea what might be happening?