2013-03-02 37 views
0

编辑:解决方法是我忘记了要执行的查询。如果你不执行查询,则什么都不会发生。初学者的错误。在php中获取并解析XML文件,然后在数据库中放入xml值

我试图让我的XML内容,并把它们放入我的数据库与PHP。我无法用成功完成这个任务,所以我尝试了一下:只是尝试将变量值插入到我的数据库表中。此外,这失败了,所以我试图从相同的数据库中,但从另一个表中获取内容,而且确实起作用。我仍然在处理我的问题以填充另一个表中的列,但它不起作用。

我的代码:

<!doctype HTML> 

<html> 
<head> 

<?php require_once("../includes/constants.php"); 
     require_once("../includes/connection.php"); 
     $connect = connectDB(); 
?> 

</head> 
<body> 

<?php 

$xml = simplexml_load_file("file.xml"); 
$test = "dit is een naam"; 
$nodes = new SimpleXMLElement('file.xml', null, true) 
     or die("cannot create"); 

foreach ($nodes->children() as $child) 
{ 
$naam = $child->name; 
$desc = $child->description; 
$sql = "INSERT INTO feeds (name, description) VALUES('". $naam ."','". $desc ."')"; 

    print_r($sql); 
} 
?> 
</body> 

</html> 

我的表(称为:饲料):

id - INT(ai) 
name - varchar 
url - varchar 
description - varchar 

提前感谢!

+0

这个帽子显示print_r($ sql);你可以显示xml文件,我看到你没有把url INSERT INTO feeds(name,description)在db中有没有默认值的url? – ddjikic 2013-03-03 01:27:32

+0

欢迎来到StackOverflow!那么你的问题到底是什么? – peterm 2013-03-03 03:03:26

回答

0

你实际上并没有在任何地方执行SQL。你需要包括

mysql_query($sql) 
+0

多么愚蠢!谢谢一堆。 – marciano 2013-03-03 18:12:45