Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/08/2011, 11:39
juanzanper
 
Fecha de Ingreso: agosto-2011
Ubicación: Sevilla
Mensajes: 18
Antigüedad: 12 años, 8 meses
Puntos: 0
Problemas con formulario bbcode y php

Hola a todos, os esplico:
Hace un tiempo me puse a intentar aprender php, y para ello empecé a hacer una web con panel de administración. pero el formulario del panel es de texto plano por lo que subir cualquier texto es bastante tedioso por el tema de que tengo que poner todas la etiquetas de atributos a mano. Por este motivo decidí poner un formulario como el de este foro con sus botones en negrita, subrayado etc.etc.

Buscando encontré este de [URL="http://www.disegnocentell.com.ar/notas2.php?id=131"]aquí[/URL]que me pareció muy interesante, por lo que me decidí a trabajar sobre el.

Sustituí el antiguo formulario de texto plano por este, os pongo los archivos que he llamado add.php (formulario) y added.php (php para subirlo a la web):

Cita:

ADD.PHP
<?php include('../bbcode/bbcode.php'); ?>
<?php
session_start();
if($_SESSION[access]!=TRUE){
header("location: ../phpmbjm/form_admi.php");
exit;
}
else
{
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='robots' content='noindex,nofollow,noarchive,noodp,nosnippe t'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Museo Betico Javier Maldonado</title>
<script src='../bbcode/bbcode.js'></script>
<style type='text/css'>
<!--
.Estilo1 {
font-family: Verdana, Arial;
font-weight: bold;
}
-->
</style>
</head>
<body onload=\"init('texto');\">
<form id='FormName' action='added.php' method='post' name='FormName' enctype='multipart/form-data'>
<table width='450' border='0' cellspacing='2' cellpadding='0'>
<tr>
<td width = '150'><div align='right'><label for='fecha'>fecha</label></div></td>
<td><input id='fecha' name='fecha' type='text' size='60' value='' maxlength='255'></td>
</tr>
<tr>
<td width = '150'><div align='right'><label for='texto'>texto</label></div></td>
<td><textarea id='texto' name='texto' rows='4' cols='40'></textarea></td>
</tr>
<tr>
<td width = '150'><div align='right'><label for='imagen'>imagen(introducir nombre.extension)</label></div></td>
<td><input id='imagen' name='imagen' type='text' size='60' value='' maxlength='255'></td>
</tr>
<tr>
<td width='150'></td>
<td><input name='foto' type='file' size='46'><br></td>
</tr>
<tr>
<td width='150'></td>
<td><div align='center'><br><input type='submit' name='submitButtonName' value='Aceptar'></div></td>
</tr>
</table>
</form>
</body>
</html>";
}
?>


ADDED.PHP
<?php include('../bbcode/bbcode.php'); ?>
<?php
session_start();
if($_SESSION[access]!=TRUE){
header("location: ../phpmbjm/form_admi.php");
exit;
}
else
{
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='robots' content='noindex,nofollow,noarchive,noodp,nosnippe t'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Museo Betico Javier Maldonado</title>
<style type='text/css'>
<!--
.Estilo1 {font-family: Verdana, Arial}
-->
</style>
</head>

<body>
<h2 align='center'><a href='index.php' class='Estilo1'>Volver al listado </a></h2>
<div align='center'><br/>";

include("connect.php");

$archivo_nombre= $_FILES['foto']['name'];
$archivo_peso= $_FILES['foto']['size'];
$archivo_tipo= $_FILES['foto']['type'];
$archivo_temporal= $_FILES['foto']['tmp_name'];
$fecha = $_POST['fecha'];
$texto = bbcode($_POST['texto']);
$imagen = $_POST['imagen'];

$query = "INSERT INTO llavpenias (id, fecha, texto, imagen)
VALUES ('', '$fecha', '$texto', '$imagen')";
$results = mysql_query($query);

$copiado=move_uploaded_file($archivo_temporal, $archivo_nombre);


if ($results)
{
if($copiado==false){
print "Error imagen";
}

echo "<br>Añadido Correctamente";
}
mysql_close();
}
?>

</div>
</body>
</html>
Hasta aquí salvo un problema que ya comentaré todo funciona correctamente. El problema que tengo por culpa de mi escaso conocimiento de PHP viene con los archivos que creé para la modificación de los textos e imagenes que subía.
Para modificar los textos subidos a la web creé los archivos update.php (otro formulario) y updated.php (php para subirlo):

Cita:
UPDATE.PHP
<?php include('../bbcode/bbcode.php'); ?>
<?php
session_start();
if($_SESSION[access]!=TRUE){
header("location: ../phpmbjm/form_admi.php");
exit;
}
else
{
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='robots' content='noindex,nofollow,noarchive,noodp,nosnippe t'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Museo Betico Javier Maldonado</title>
<script src='../bbcode/bbcode.js'></script>
<style type='text/css'>
<!--
.Estilo1 {
font-family: Verdana, Arial;
font-weight: bold;
}
-->
</style>
</head>
<body onload=\"init('texto');\">
<div align='center'>";

include('connect.php');
$ID = $_GET['ID'];

$qProfile = "SELECT * FROM llavpenias WHERE ID='$ID' ";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
extract($row);
$fecha = stripslashes($fecha);
$texto = stripslashes($texto);
$imagen = stripslashes($imagen);

mysql_close();

echo "
</div>
<form id='FormName' action='updated.php' method='post' name='FormName' enctype='multipart/form-data'>
<table width='450' border='0' cellspacing='2' cellpadding='0'>
<tr>
<td width = '150'><div align='right'><label for='fecha'>fecha</label></div></td>
<td><input id='fecha' name='fecha' type='text' size='60' value='$fecha' maxlength='255'></td>
</tr>
<tr>
<td width = '150'><div align='right'><label for='texto'>texto</label></div></td>
<td><textarea id='texto' name='texto' rows='4' cols='40'>$texto</textarea></td>
</tr>
<tr>
<td width = '150'><div align='right'><label for='imagen'>imagen(introducir nombre.extension)</label></div></td>
<td><input id='imagen' name='imagen' type='text' size='60' value='$imagen' maxlength='255'></td>
</tr>
<tr>
<td width='150'></td>
</tr>
<tr>
<td width='150'></td>
<td><div align='center'><br><input type='submit' name='submitButtonName' value='Aceptar'></div></td>
</tr>
</table>
</form>
<div align='center' class='Estilo1'><a href='index.php'>Volver sin modificar nada</a></div>
</body>
</html>";
}
?>


UPDATED.PHP
<?php include('../bbcode/bbcode.php'); ?>
<?php
session_start();
if($_SESSION[access]!=TRUE){
header("location: ../phpmbjm/form_admi.php");
exit;
}
else
{
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='robots' content='noindex,nofollow,noarchive,noodp,nosnippe t'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Museo Betico Javier Maldonado</title>
</head>

<body>
<h2 align='center'><a href='index.php' class='Estilo1'>Volver al listado </a></h2>
<div align='center'><br/>";

include("connect.php");

$ID = $_POST['ID'];
$fecha = $_POST['fecha'];
$texto = $_POST['texto'];
$imagen = $_POST['imagen'];

$update = "UPDATE llavpenias SET fecha = '$fecha', texto = '$texto', imagen = '$imagen' WHERE ID='$ID' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Subido Correctamente";
} mysql_close();
}
?>
</body>
</html>
No consigo modificar nada, por lo que creo que el problema está en que tengo que modificar algo en el código que he puesto en negrita más arriba, pero no sé lo que es.

Otro problema secundario es que este formulario no reconoce caracteres especiales, eñes, acentos etc. etc.

Si alguien me pudiese orientar le estaría muy agradecido.
un saludo y gracias