0
The following PHP code performs a click search and displays all required XML data, however, even with the PHP script to increase and decrease XML values in 1
, when clicking on +
or -
, it just returns the main page(e.php
) without having effected the change.
How can I make such changes within the form below so that an initial limit equal to 0
and a final limit equal to media_total
?
PHP file: e.php
<meta charset="UTF-8">
<style type="text/css">body{background-color: rgba(25,25,25,1); color: rgba(255,255,255,0.5);}</style>
<form action="e.php" method="post"><input type="hidden" name="status" value="Acompanhando"/><input type="submit" name="submit" value="Acompanhando"/></form>
<?php
if(isset($_POST['submit'])){
$string = file_get_contents("minha_lista.xml");
$xml = simplexml_load_string($string);
$erro = 0;
$i = 1;
echo "<center>";
foreach($xml->lista AS $val){
if($val->status==$_POST['status']){
$titulo = $val->titulo;
$media_acompanhada = $val->media_acompanhada;
$valor_da_media_acompanhada_positiva = 1;
$valor_da_media_acompanhada_negativa = 1;
echo "o Título é <code style='color: rgba(255,130,0,1);'>".$titulo."</code> e a Média acompanhada é <code style='color: rgba(0,255,255,1);'>".$media_acompanhada."</code>";
?>
<form action="" method="post">
<label><button hidden name="media_acompanhada[<?php echo $valor_da_media_acompanhada_positiva++; ?>]" value="<?php echo $media_acompanhada+1; ?>"></button>+</label>
<div class="mudanca_de_cursor" style="display: inline;">/</div>
<label><button hidden name="media_acompanhada[<?php echo $valor_da_media_acompanhada_negativa++; ?>]" value="<?php echo $media_acompanhada-1; ?>"></button>-</label>
</form>
<?php
if (isset($_POST['media_acompanhada'])){
$medias_acompanhadas = (array) $_POST['media_acompanhada'];
$carregador_xml = simplexml_load_file('minha_lista.xml');
$funcao = fopen("minha_lista.xml", "wb");
foreach ($medias_acompanhadas as $num => $media_acompanhada){
$valor_da_media_acompanhada = 1;
foreach ($carregador_xml->children() as $lista){
if ($valor_da_media_acompanhada++ == $num ){
$lista->media_acompanhada = $media_acompanhada;
break 1;
}
}
}
fwrite($funcao, $carregador_xml->asXML());
fclose($funcao);
echo '<script type="text/javascript">window.location.href=window.location.href;</script>';
}
?>
<?php
$erro++;
}
}
if($erro == 0){
echo "Nenhum valor encontrado";
}
echo "</center>";
}
?>
XML file: minha_lista.xml
<?xml version="1.0" encoding="UTF-8"?>
<banco_de_dados>
<lista>
<titulo>A</titulo>
<media_acompanhada>6</media_acompanhada>
<media_total>8000</media_total>
<status>Acompanhando</status>
</lista>
<lista>
<titulo>C</titulo>
<media_acompanhada>10</media_acompanhada>
<media_total>40000</media_total>
<status>Acompanhando</status>
</lista>
</banco_de_dados>
Apparently there is a problem here, debugging the found code: Notice: Undefined variable: value_media_accompanied positive and also value_da_media_accompanied negative_negative
– Junior Moreira
I added the missing data, but the problem still remains.
– Rick