A ver si me podéis ayudar entonces :)
Este es el archivo del formulario desde donde se envía:
compose.php
Código PHP:
<?php
require_once '../includes/conn.php';
include('header.php');
$titulo = '';
$cuerpo = '';
$article = '';
$autor_id = '';
if (isset($_POST['a'])
and $_POST['a'] == 'edit'
and isset($_POST['article'])
and $_POST['article']) {
$sql = "SELECT titulo,cuerpo,autor_id FROM not_main WHERE not_id=" . $_POST['article'];
$result = mysql_query($sql,$conn)
or die('No se pueden obtener los datos del artículo; ' . mysql_error());
$row = @mysql_fetch_array($result);
$titulo = $row['titulo'];
$cuerpo = $row['cuerpo'];
$article = $_POST['article'];
$autor_id = $row['autor_id'];
}
require_once 'header.php';
?>
<form method="post" action="transact-article.php">
<h2>Escribir documento</h2>
<p>Titulo:</p>
<p><input type="text" class="titulo" name="titulo" size="93" maxlength="500" value="<?php echo htmlspecialchars($titulo); ?>" /></p>
<p>Texto:</p>
<p><textarea class="cuerpo" name="cuerpo" rows="20" cols="70"><?php echo htmlspecialchars($cuerpo); ?></textarea></p>
<p>
<?php
echo '<input type="hidden" name="article" value="' . $article . "\" />\n";
if ($_SESSION['access_lvl'] < 2) {
echo '<input type="hidden" name="autor_id" value="' . $autor_id . "\" />\n";
}
if ($article) {
echo '<input type="submit" class="submit" name="action" ' . "value=\"Guardar cambios\" />\n";
} else {
echo '<input type="submit" class="submit" name="action" ' . "value=\"Enviar\" />\n";
}
?>
</p>
</form>
<?php require_once 'footer.php'; ?>
Este es el archivo transact-article:
Código PHP:
<?php
session_start();
require_once '../includes/conn.php';
require_once 'http.php';
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'Enviar':
if (isset($_POST['titulo'])
and isset($_POST['cuerpo'])
and isset($_SESSION['autor_id']))
{
$sql = "INSERT INTO not_main (not_id,titulo,cuerpo,autor_id,fecha_envio) VALUES ('','" . $_POST['titulo'] . "','" . $_POST['cuerpo'] . "','" . $_SESSION['autor_id'] . "', NOW())";
mysql_query($sql,$conn)
or die('No se puede enviar el artículo; ' . mysql_error());
}
redirect('index.php');
break;
case 'Editar':
redirect('compose.php?a=edit&article=' . $_POST['article']);
break;
case 'Guardar los cambios':
if (isset($_POST['titulo']) and isset($_POST['cuerpo']) and isset($_POST['articulo']))
{
$sql="UPDATE not_main " . "SET title='" . $_POST['titulo'] . "', cuerpo='" . $_POST['cuerpo'] . "', fecha_envio='" . date("d-m-Y H:i:s", time()) . "' " . "WHERE not_id=" . $_POST['article'];
if (isset($_POST['autor_id'])) {
$sql .= " AND autor_id=" . $_POST['autor_id'];
}
mysql_query($sql, $conn)
or die('No se puede actualizar el artículo; ' . mysql_error());
}
if (isset($_POST['autor_id'])) {
redirect('cpanel.php');
} else {
redirect('pending.php');
}
break;
case 'Retroceder':
if ($_POST['article']) {
$sql = "UPDATE not_main " . "SET esta_publicada=0,fecha_publicacion=''" . "WHERE not_id=" . $_POST['article'];
mysql_query($sql,$conn)
or die('No se puede retroceder al artículo; ' . mysql_error());
}
redirect('pending.php');
break;
case 'Borrar':
if ($_POST['article']) {
$sql = "DELETE FROM not_main " . "WHERE esta_publicada=0 " . "AND " . "not_id=" . $_POST['article'];
mysql_query($sql,$conn)
or die('No se puede borrar el artículo; ' . mysql_error());
}
redirect ('pending.php');
break;
case 'Enviar comentario':
if (isset($_POST['article'])
and $_POST['article']
and isset($_POST['comment'])
and $_POST['comment'])
{
$sql = "INSERT INTO not_comments " . "(not_id,fecha_comment,comment_user,comment_text) " . "VALUES (" . $_POST['article'] . ",'" . "VALUES (" . $_POST['article'] .",'" . date("Y-m-d H:i:s", time()) . "'," . $_SESSION['autor_id'] . ",'" . $_POST['comment'] . "');";
mysql_query($sql,$conn)
or die('No se puede añadir un comentario; ' . mysql_error());
}
redirect('viewarticle.php?article=' . $_POST['article']);
break;
case 'Eliminar':
if (isset($_GET['article']) and isset($_SESSION['autor_id']))
{
$sql = "DELETE FROM not_main " . "WHERE not_id=" . $_GET['article'] . " AND autor_id=" . $_SESSION['autor_id'];
mysql_query($sql,$conn)
or die('No se puede eliminar el artículo; ' . mysql_error());
}
redirect('cpanel.php');
break;
}
} else {
redirect('index.php');
}
?>
Pues ese es el código de los dos archivos a ver qué sale... porque funcionó y después volvió a dar el error... :?
Gracias :)