pb_
pb_

Reputation: 492

Unable to edit xml file content in php

<?php 
$picid= $_GET['id']; 
intval($picid);
$file="data.xml";
echo $picid; //output is 121 (say)
$data= new SimpleXMLElement($file, null, true);
$data->score[$picid]=$data->score[$picid]+3;
file_put_contents($file, $data->asXML());
?>

The xml file changes to

<score 121="3">0</score>

on the score[0] tag.

Whereas I want the output

<score>3</score>

on the score[121] tag.

But when I change my code to

<?php 
$picid= $_GET['id']; 
intval($picid);
$file="data.xml";
echo $picid; //121 is printed (say)
$data= new SimpleXMLElement($file, null, true);
$data->score[121]=$data->score[121]+3;
echo $data->score[121];
file_put_contents($file, $data->asXML());
?>

i am gettng the desired output. Why?

Upvotes: 2

Views: 125

Answers (1)

apoq
apoq

Reputation: 1454

your intval returns to void.

Try:

$picid = intval($picid);

Upvotes: 2

Related Questions