Good evening, today I've been trying to work out a formula on submitting my xml data into my MySQL database, this is something I've not dome before but I've been trying very hard and have unfortunately been unsuccessful, I get the following error message, Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in locations.php
on line 9
please find below my xml file which is a sample, and my PHP code, if anyone is able to help I really appreciate it, thank you very much
xml
<?xml version="1.0" encoding="utf-8"?>
<datafile>
<data name="Area One">
<category>Place One</category>
<title name="One" size="100" color="red" />
<title name="Two" size="150" color="yellow" />
<title name="Three" size="200" color="pink" />
<title name="Four" size="250" color="green" />
<title name="Five" size="300" color="purple" />
</data>
<data name="Area Two">
<category>Place Two</category>
<title name="One" size="500" color="orange" />
<title name="Two" size="550" color="blue" />
<title name="Three" size="600" color="silver" />
<title name="Four" size="650" color="white" />
<title name="Five" size="700" color="gold" />
</data>
</datafile>
php
$xml = simplexml_load_file("locations.xml")
or die("Error: Cannot create object");
foreach($xml->children() as $data) {
echo $data->('data name') . ", ";
echo $data->category . ", ";
echo $data->('title name') . $data->('size') . $data->('color') . "<br>";
}
$sql = "INSERT INTO data (data-name, category, information)
VALUES ('', '', '')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
What I've been trying to do is to insert each data name from the xml file into it's own mysql record "data name" to go into "data-name" "category" to go into "category"
and when it comes to "title name", "size" and "color" they all share the "information" field, for example
"one, 100, red
two, 150, yellow
three, 200, pink
four, 250, green
five, 300, purple"
I do apologize in advance if in the way I've explained this is confusing, please feel free to ask me any questions, thank you very much