我有这段代码。这只是为了测试目的,所以你不需要告诉我使用参数绑定和准备好的语句和PDO来避免SQL注入。为什么PHP会为此代码发出未定义的变量消息?
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
}
}
}
}
这是什么代码是为了完成:如果变量$name
是已经在数据库中的值,什么也不做。否则,将其添加到数据库。
不过,我收到一条错误消息:注意:未定义的变量:在/var/www/teste/index5.php
名字我的意思是,变量是那里。任何想法可能发生什么?
呼应$名称= $节点 - >的nodeValue后的变量;看看输出是什么 – 2012-03-14 19:30:15
以及如果说$名不总是设置。 – 2012-03-14 19:31:12