WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Get help with adding and updating XML databases.

elliott

New member

0

0%

Status

Offline

Posts

36

Likes

0

Rep

0

Bits

190

5

Months of Service

0%
Hello, I am receiving a blank screen instead of errors while attempting to add and update XML data in PHP to enhance my skills. Esteemed mentors, could you please review my code and guide me? I would greatly appreciate it if you could point out where I may have missed something if you provide a working code. Thank you.

**index.php file**
```php
<?php
include("config.php");
$file = simplexml_load_file("musteri.xml");
foreach ($file as $key => $value) {
$musteriID = $value->id;
$musteriAdi = $value->adi;
$musteriSoyadi = $value->soyadi;
$musteriMeslek = $value->meslek;
$musteriYasi = $value->yas;

$control = $db->prepare("SELECT * FROM musteriler WHERE musteriID=?");
$control->execute(array($musteriID));
$say = $control->rowCount();

if ($say == 0) {
$veriler = $control->fetchAll(PDO::FETCH_ASSOC);
foreach ($veriler as $veri ) {
$sql = $db->prepare("UPDATE musteriler SET musteriAdi=?, musteriSoyadi=?, musteriMeslek=?, musteriYasi=? WHERE musteriID=? VALUES(?, ?, ?, ?, ?)");
$sql->execute(array($musteriAdi, $musteriSoyadi, $musteriMeslek, $musteriYasi, $musteriID));
if ($sql->rowCount() > 0 ) {
echo "Successful update";
} else {
echo "Error occurred";
}
}
} else {
$sql = $db->prepare("INSERT INTO musteriler SET musteriID=?, musteriAdi=?, musteriSoyadi=?, musteriMeslek=?, musteriYasi=?");
$sql->execute(array($musteriAdi, $musteriSoyadi, $musteriMeslek, $musteriYasi));
if ($sql->rowCount() > 0) {
echo "Record successful";
$file = file_get_contents("$resim");
$kayit = fopen('images/' . $resim_yol, "w+");
fwrite($kayit, $veri2);
fclose($kayit);
}
}
}
echo "";
?>

```

**config.php file**
```php
<?php
try {
$db = new PDO ("mysql:host=localhost;dbname=erdal", "root", "");
} catch (PDOException $e) {
print $e->getMessage();
}
?>
```

**XML file**
```xml
1 Mert Buldur Orman Müh. 21
2 Mustafa Y?ld?z Avukat 30
```
 

249

6,622

6,642

Top