No puedo usar bases de datos, por lo que me tengo que limitar a ficheros de texto.
Despues de 6 horas buscando por san google sistemas de este tipo ya hechos, cada uno daba un problema diferente. Este ultimo me ha gustado mucho y, la verdad, me gustaria poder utilizarlo, pero muestra los siguientes 3 mensajes cuando introduzco un comentario:
Notice: Undefined offset: 4 in C:\wamp\www\Portal\guestbook\file.php on line 15
Notice: Undefined offset: 4 in C:\wamp\www\Portal\guestbook\file.php on line 18
Notice: Undefined offset: 4 in C:\wamp\www\Portal\guestbook\file.php on line 21
Pongo a continuacion los dos ficheros que estoy utilizando:
file.php
Código:
mod_file.php<?php /* Created by Abimael Rodriguez www.bravefire.com v 1.0 */ $file = "guestbook"; $gInfo = ""; $rFile = @fopen($file,"r"); $file_array = @file($file); for($i = count($file_array); $i >= 0; $i--){ if(strstr($file_array[$i], "%name%")){ $gInfo .= "<fieldset><legend><b>" . preg_replace("/%name%/", "", $file_array[$i]) . "</b>"; } if(strstr($file_array[$i], "%title%")){ $gInfo .= "<i>" . preg_replace("/%title%/", "", $file_array[$i]) . "</i></legend>"; } if(strstr($file_array[$i], "%comment%")){ $gComment = preg_replace("/%comment%/", "", $file_array[$i]); $wrapComment = wordwrap($gComment, 68, "<br />", true); $gInfo .= $wrapComment . "</fieldset><br>"; } } @fclose($rFile); ?> <html> <head> <title>GUESTBOOK FILE</title> </head> <body topmargin=0 leftmargin=0> <form name="guestForm" action="mod_file.php" method="post"> <input type="hidden" name="whatType" value="fileInput"> <input type="hidden" name="action" value="<?php echo $_SERVER["PHP_SELF"] ?>"> <table align="center"> <tr> <th colspan="2">Add info into file</th> </tr><tr> <td align="right">Name:</td> <td><input type="text" name="Name" size=30 maxlength=25></td> </tr><tr> <td align="right">Title:</td> <td><input type="text" name="Title" size=30 maxlength=25></td> </tr><tr valign="top"> <td align=right>Comment:</td> <td><textarea name="Comment" rows="5" cols="40"></textarea></td> </tr><tr> <td colspan=2 align="right"> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <div align="center"> --------------------------------------------------------------------- </div> <table align="center" width="500"> <tr> <td> <?php echo $gInfo; ?> </td> </tr> </table> </body> </html>
Código:
Gracias anticipadas. Estoy seguro que es cualquier tonteria, pero no logro encontrar el fallo y la verdad, no se mucho de php, aprendí lo basico y en codigos medio largos me pierdo. <?php /* Created by Abimael Rodriguez www.bravefire.com v 1.0 */ foreach($_REQUEST as $key => $value){ $value = trim($value); if(!empty($value)){ $$key = $value; } } if($whatType == "fileInput" && !empty($Name) && !empty($Title) && !empty($Comment)){ $file = "guestbook"; $gInfo = "\r\n %comment% " . preg_replace("/\r\n/", "<br />", htmlentities($Comment, ENT_QUOTES)) . "\r\n" . "%title% " . htmlentities($Title, ENT_QUOTES) . "\r\n" . "%name% " . htmlentities($Name, ENT_QUOTES) . "\r\n"; $wFile = fopen($file, "a+"); fwrite($wFile, $gInfo); fclose($wFile); } if($whatType == "databaseInput" && !empty($Name) && !empty($Title) && !empty($Comment)){ require_once("config.php"); $sql_guestbook = "INSERT INTO `tbl_guestbook`(`Name`, `Title`, `Comment`) VALUES( '".htmlentities($Name, ENT_QUOTES)."', '".htmlentities($Title, ENT_QUOTES)."', '".htmlentities($Comment, ENT_QUOTES)."' )"; $result_guestbook = mysql_query($sql_guestbook) or die(mysql_error()); } header("Location: $action"); ?>