ok i tried making the edit process in one function
its working but not fully do to my limited understanding of
sessions i guess.
when i keep one field empty it will givem this warning
Warning: Cannot modify header information - headers already sent by (output started at E:\Practise\test4\config.php:9) in E:\Practise\test4\edit2.php on line 21
this is the edit function.
PHP Code:function article_update($article_id , $article)
{
if($article_id){
$sql = "SELECT article_name, summary, author, article_content, notes, date_added, status
FROM articles WHERE articleID = '".$article_id."'";
$res = my_query($sql);
if(mysql_num_rows($res) != 0)
{
$num = mysql_fetch_assoc($res);
return $num;
}
else
return false;
}
elseif($article){
if(empty($article["article_name"]))
{
$_SESSION["error"] = "Please enter The Article Name";
return false;
}
else if(empty($article["summary"]))
{
$_SESSION["error"] = "Please enter a summary";
return false;
}
else if(empty($article["article_content"]))
{
$_SESSION["error"] = "Please enter a content";
return false;
}
$sql = "UPDATE articles SET";
$sql .=" article_name = '".$article["article_name"]."'";
$sql .=", summary = '".$article["summary"]."'";
$sql .=", author = '".$article["author"]."'";
$sql .=", article_content = '".$article["article_content"]."'";
$sql .=", notes = '".$article["notes"]."'";
$sql .=", status = '".$article["status"]."' WHERE articleID = '".$article["articleID"]."'";
my_query($sql);
return true;
}
return true;
}
and this is the edit1.php form
and the edit2.phpPHP Code:<?php
include_once "common.php";
$article_id = $_GET['article_ID'];
$article = article_update($article_id , NULL);
if(!$article)
{
echo "article doesn't exist";
}
else
{
echo '<html><body>
<form action="edit2.php" method="post">
<p>
<input name="articleID" type="hidden" id="articleID" value="';
echo $article_id;
echo ' "/>
<br />
Article Name <br />
<input name="articlename" type="text" id="articlename" value="';
echo $article["article_name"];
echo ' " size="80" maxlength="80" />
<br />
Summary <br />
<input name="summary" type="text" id="summary" value="';
echo $article["summary"];
echo ' "size="80" />
<br />
Author <br />
<input name="author" type="text" id="author" value="';
echo $article["author"];
echo '" size="80" maxlength="30" />
<br />
Article Content </p>
<p>
<textarea name="articlecontent" cols="80" rows="7" id="articlecontent">';
echo $article["article_content"];
echo '</textarea>
<br />
<br />
Notes <br />
<input name="notes" type="text" id="notes" value="';
echo $article["notes"];
echo '" size="80" maxlength="300" />
<br />
Date Posted <br />
<input name="date" type="text" id="date" value="';
echo $article["date_added"];
echo '" size="80" maxlength="30" />
<br />
Status <br />
<input name="status" type="text" id="status" value="';
echo $article["status"];
echo '" size="7" maxlength="80" />
<br />
<input name="" type="submit" value="Submit" />
</p>
</form>
</body>
</html>';
}
?>
i hope its a right way to impliment ?PHP Code:<?php
include_once "common.php";
$article["articleID"] = $_POST['articleID'];
$article["article_name"] = $_POST['articlename'];
$article["summary"] = $_POST['summary'];
$article["author"] = $_POST['author'];
$article["article_content"] = $_POST['articlecontent'];
$article["notes"] = $_POST['notes'];
$article["status"] = $_POST['status'];
if(article_update(NULL , $article))
{
echo "Ok";
//success
//do whatever you want to do on succes
}
else
{
//error
$_SESSION["article"] = $article;
header("Location: edit1.php");
}
?>
there is also another way (i think ) is to call function article_read($article_id, $frontend = false)
from function
article_update($article_id , $article)
well i guess its possible, but i wasnt lucky. :(
