I had been inserting successfully into database but it is not inserting anything, I did not change the code since then actually.
What can be the reason?
while ($row = mysql_fetch_array($new_entries)){
$anzeigen_id = $row[0];
$firma_id = $row[1];
$xml_filename = "xml/".$anzeigen_id.".xml";
$dom = new DOMDocument();
$dom->load($xml_filename);
$value = $dom->getElementsByTagName('FormattedPositionDescription');
foreach($value as $v){
$text = $v->getElementsByTagName('Value');
foreach($text as $t){
$anzeige_txt = $t->nodeValue;
$anzeige_txt = utf8_decode($anzeige_txt);
$sql = "INSERT INTO testing (`firmen_id`,`anzeige_id`,`anzeige_txt`) VALUES ('$firma_id','$anzeigen_id','$anzeige_txt')";
$sql_inserted = mysql_query($sql);
if($sql_inserted){
echo "'$anzeigen_id' from $xml_filename inserted<br />";
}
}
}
}
Well I will post an answer because it will be more clear to ask you some code example, etc..
First of all, when you got an unexplicable case like this: you should debug!
In your case, you display a message when the query success. But what if the query failed? You should handle an error message to see what’s going on. Something like that:
There will be an exception when a query failed. You will have the error message (
mysql_error()) and the query that failed ($sql).What could be a problem, is that you didn’t escape value you put inside your query. So, if there is a
'inside a variable, it will break the query. You should escape them:So you will have a final code like this:
By the way, as I told you please, don’t use
mysql_*functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi – this article will help you decide which. If you choose PDO, here is a good tutorial.