boas, mais um problema que encontrei, dos muitos que ainda tenho
tenho um sitio onde diz as noticias que tenho onde posso apagar e modificar
o problema é que ele nao modifica, so apaga, ele ao modificar diz a mensagem
"falta imformaçao"
que é na parte da validaçao
e o formulario
tenho um sitio onde diz as noticias que tenho onde posso apagar e modificar
o problema é que ele nao modifica, so apaga, ele ao modificar diz a mensagem
"falta imformaçao"
que é na parte da validaçao
Código:
<?php
include $_SERVER['DOCUMENT_ROOT'].'/tfc/layout.php';
include $_SERVER['DOCUMENT_ROOT'].'/tfc/common.php';
//quick admin session check
admin_check();
//dynamic form selet menu
//for categories
function cat_list($selected)
{
//perform the query
$sql=mysql_query("select * from artigo_categoria");
//begin slelect menu
echo "<select name=\"cat_id\" >\n";
echo "<option value=\"NULL\">Please select</options>";
//do the loop for the categories
while($row=mysql_fetch_array($sql))
{
echo "<option value=\" ".stripslashes($row[cat_id])."\"";
//if $selected is equal to current row, select this item in menu
if($selected==$row[cat_id])
{
echo "selected";
}
echo ">".stripslashes($row[cat_name])."</options>\n";
}
//close select statement
echo "</select>\n";
}
//initiate myheader function
titulo("Modify or Delete news categories");
//star switch
switch($_REQUEST['req'])
{
//modify category form
case "mod_news_article":
$sql=mysql_query("Select * from artigo where article_id='{$_GET['article_id']}'");
$row=mysql_fetch_assoc($sql);
include $_SERVER['DOCUMENT_ROOT'].'/tfc/admin/news_modify_form.html';
break;
//modify category query
case "update_news_article":
//form validation
if(!$_POST['article_title'] ||
!$_POST['article_caption'] ||
!$_POST['article_body'] ||
$_POST['cat_id']==0)
{
echo '<p align="center">Missing form information!</p>'.
'<p align="center">Please use you browser back button and complete the form.</p>';
corpo();
exit();
}
//update query
$sql=mysql_query("UPDATE artigo SET
article_title='{$_POST['article_title']}',
article_caption='{$_POST['article_caption']}',
article_body='{$_POST['article_body']}',
cat_id='{$_POST['cat_id']}'
WHERE article_id='{$_POST['article_id']}'
");
//error check
if (!$sql)
{
echo "Error performing query:".mysql_error();
}else{
echo '<p align="center">Article Update!</p>';
echo '<p align="center"><a href="/TFC/admin/mod_news_article.php">Modify Another News Article</a></p>';
}
break;
//delete article confirmation
case "confirm_delete":
echo '<p align="center">Are you sure you want to delete this article</p>';
echo '<p align="center"><a href="/TFC/admin/mod_news_article.php?req=delete_news_article&article_id='.$_GET['article_id'].'">Yes</a> |<a href="/TFC/admin/mod_news_article.php">No</a></p>';
break;
//delete article query
case "delete_news_article":
$sql=mysql_query("DELETE FROM artigo WHERE article_id='{$_GET['article_id']}'");
if(!$sql)
{
echo "erro performing query:".mysql_error();
}else{
echo '<p align=center>category deleted!</p>';
echo '<p align=center><a href="/tfc/admin/mod_news_article.php">Modify another category</a></p>';
}
break;
//defaul case: modify/delete index
default:
//define alternating row colors
$color1="#E6E6E6";
$color2="#F4FEFF";
//set row_count
$row_count=0;
//build top of the table
echo '<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Modify or Delete News Articles</font></p>';
echo '<table align="center" width="90%" border="0" cellpadding="4" cellspacing="0">';
echo '<tr>';
echo '<td width="300">Article</td>';
echo '<td width="150">Article Date</td>';
echo '<td width="5">Modify</td>';
echo '<td width="5">Delete</td>';
echo '</tr>';
//perform mysql query to get rows
$sql=mysql_query("SELECT * FROM artigo") OR DIE (mysql_error());
while($row=mysql_fetch_array($sql))
{
//determine which row color to use
$row_color=($row_count % 2) ? $color1 : $color2;
//display table row with data
echo '<tr bgcolor="'.$row_color.'">';
echo '<td width="300"><a href="/tfc/admin/articles.php?req=read&article_id='.$row['article_id'].'">'.$row['article_title'].'</a></td>';
echo '<td width="150">'.$row['article_date'].'</td>';
echo '<td width="5"><a href="/tfc/admin/mod_news_article.php?req=mod_news_article&article_id='.$row['article_id'].'">Modify</a></td>';
echo '<td width="5"><a href="/tfc/admin/mod_news_article.php?req=confirm_delete&article_id='.$row['article_id'].'">Delete</a></td>';
echo "</tr>";
$row_count++; //increment row count
}//end while loop
echo '</table>';
break;
}
//corpo();
?>
Código:
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><font size="4" face="Verdana, Arial, Helvetica, sans-serif">News Article Modification</font></p>
<form method="post" action="/TFC/admin/mod_news_article.php">
<table width="51% "border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td width="25%" align="left" valign="top" nowrap="nowrap">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Article Title</strong></font>
</td>
<td width="75%">
<input name="Article_title" type="text" id="article_title" value="<?=stripslashes($row['article_title']);?>" size="60" />
</td>
</tr>
<tr>
<td align="left" valign="top" nowrap="nowrap">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Article Category</strong></font>
</td>
<td>
<?php cat_list($row['cat_id']);?>
</td>
</tr>
<tr>
<td align="left" valign="top" nowrap="nowrap">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Article Caption</strong></font>
</td>
<td><textarea name="article_caption" cols="60" id="article_caption"><?=stripslashes($row['article_caption']);?></textarea></td>
</tr>
<tr>
<td align="left" valign="top" nowrap="nowrap">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Full Article</strong></font>
</td>
<td><textarea name="article_body" cols="60" rows="15" id="article_body"><?=stripslashes($row['article_body']);?></textarea></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td><div align="center">
<input name="article_id" type="hidden" id="article_id" value="<?=$row['article_id'];?>" />
<input name="req" type="hidden" id="req" value="update_news_article" />
<input type="submit" name="submit" value="Modify News Article!" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>