All pastes #565134 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-13 21:48 UTC
rendered paste body
<?php

$xml = simplexml_load_file("projekt.xml");
$xmltmp = $xml->addChild('usuario');
unset($xml);
unset($xmltmp);




//guarda el nuevo comentario
$pname  = $_POST['pname'];
$pmessage   = $_POST['pmessage'];
$pid = $_POST['pid'];
$flag = 0;

if($pid == '001')
{
	if(strlen($pmessage) > 150)
		{
		errorPage('Error: El mensaje excede el numero de caracteres permitidos.');
		$flag = 1;
		}
	if(empty($pmessage))
		{
		errorPage('Error: Debe ingresar un mensaje.');	
		$flag = 1;
		}
        if($pmessage == "Ingresar mensaje...")
		{
		errorPage('Error: Debe ingresar un mensaje.');
                $flag = 1;
		}	
	if(empty($pname))
		{
		errorPage('Error: Debe ingresar un nombre.');
		$flag = 1;
		}
	if(!($flag))
		{
		$pmessage = str_replace("<","",$pmessage);
		$pmessage = str_replace(">","",$pmessage);
		$pmessage = str_replace("\n","<br>",$pmessage);
		$sxe = simplexml_load_file("projekt.xml");
		$ids = count($sxe->xpath('/forum/post'));
		$ids++;
		}
}
unset($sxe,$ids);

// Carga projekt.xml y lee <ids>
$sxe = simplexml_load_file("projekt.xml");
$ids = count($sxe->xpath('/forum/post'));
	
// Carga Array messages[]
for ($idss=1; $idss <= $ids;) {

	foreach($sxe->xpath('/forum/post[@id='.$idss.']/message') as $item) {
	$message[$idss] = $item;
	}
$idss++;
}
//----------------------

// Carga Array author[]
for ($idss=1; $idss <= $ids;) {
			  
	foreach($sxe->xpath('/forum/post[@id='.$idss.']/author') as $item) {
	$author[$idss] = $item;
	}
$idss++;
}
//----------------------

// Carga Array date[]
for ($idss=1; $idss <= $ids;) {
		       
		       foreach($sxe->xpath('/forum/post[@id='.$idss.']/date') as $item) {
	$date[$idss] = $item;
	}
$idss++;
}
//----------------------
?>
	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1//EN">
<html>
<head>
<title>GuestBook 0.1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<link rel="stylesheet" type="text/css" href="projekt.css" />

<center>
<body bgcolor="#EEEEEE">
<?php
// Mustra el contenido del xml

for($idss=1; $idss <= $ids;){

echo '<center><div class="guestbook1">';
echo $author[$idss].'<br>';
echo '<small>'.$date[$idss].'</small><br>';
echo '<div class="guestbook2"><br>'.$message[$idss].'</br></div>';
echo '</div></center><br>';
$idss++;
}

?>


<div class="guestbook3" align="center"><form action="projekt.php" method="post" id="commentform" class="commentform">
<p><input type=hidden name="pid" value="001"></p>
<p><label>Nombre: </label><input id="pname" name="pname" maxlength="30" size="41"></p>
<p><textarea onfocus="this.value=''; this.onfocus=null;" id="pmessage" name="pmessage" rows="6" cols="60">Ingresar mensaje...</textarea> <p>
<input type="submit" value="        Enviar       "></form></div>
</div>



</body>
</html>

<?php

function errorPage($text)
	{
	echo '<div class="error">'."\n";
	echo '<h1 align="center">'.$text.'</h1>'."\n";
	echo '</div><br>'."\n";
	}
?>