Hi,
I want to update some existing records in an sql database and am having some problems. I have one script which lists all articles currently in the database (editarticlelist.php):
include "admin_header.php";
include "db_connect.php";
// Open DB and init cutoff
$link = opendb();
//$cutoff = strtotime("-".$max_days." day");
//$cutoff = date("Y-m-d H:i",$cutoff);
// Get all article titles in timeframe and that are published
$query = "SELECT * FROM articles";
//$query = $query." AND pubdate >= \"$cutoff\"";
$result = mysql_query($query,$link)
or die("Query failed: $query");
echo "<h3>Please select article to edit</h3><p>";
// Display each article title
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
PRINT <<<HTML
<b><a href="editarticle2.php?article_id=$line[article_id]">
$line[headline] </b></a>          
<a href="deletearticle.php?article_id=$line[article_id]">delete</a>
<br>$line[subheadline]<br>
<i>created by: <b>$line[editor]</b>
  category: <b>$line[section]</b>
  published on: $line[created]<p>
HTML;
} // End while
mysql_close($link);
include('admin_footer.php');
?>
and i have another which displays the selected article in a form ready for updating (editarticle2.php):
<?php
include "admin_header.php";
//include "db_connect.php";
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!@mysql_select_db('chronicle')) {
exit('<p>Unable to locate the chronicle ' .
'database at this time.</p>');
}
if(isset($_POST['submit']))
{
$article_id = $POST['article_id'];
$headline = $POST['headline'];
$subheadline = $POST['subheadline'];
$content = $POST['content'];
$sql = ("UPDATE articles SET headline='$headline', subheadline='$subheadline', content='$content' WHERE article_id='$article_id'");
$result = mysql_query($sql) or die("$sql failed: " . mysql_error());
echo "($sql)";
echo "<b>Thank you! News UPDATED Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=editarticlelist.php>";
}
else
{
$article_id = $_GET[article_id];
$sql = ("SELECT * FROM articles WHERE article_id=$article_id");
$result = mysql_query($sql) or die("$sql failed: " . mysql_error());
$myrow = mysql_fetch_assoc($result);
$headline = $myrow["headline"];
$subheadline = $myrow["subheadline"];
$content= $myrow["content"];
?>
<br>
<h3>::Edit News</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="article_id" value="<? echo $myrow[article_id]?>">
headline<?php echo $article_id ?>: <input name="headline" size="40" maxlength="255" value="<?php echo $headline; ?>">
<br>
subheadline: <textarea name="subheadline" rows="7" cols="30"><?php echo $subheadline; ?></textarea>
<br>
content: <textarea name="content" rows="7" cols="30"><?php echo $content; ?></textarea>
<br>
<input type="submit" name="submit" value="Update News">
</form>
<?php } ?>
<?php include('admin_footer.php'); ?>
the form displays fine, with the data populated. I change the data and press submit, I get the update successful method, however the records dont change in my database. the (echo $sql) query reads :
(UPDATE articles SET headline='Sony cuts price of PlayStation 3', subheadline='Sony has cut the price of its best-selling PlayStation 2 (PS2) by $20 in the US.', content='The pircs' WHERE article_id='')Thank you! News UPDATED Successfully!
You'll be redirected to Home Page after (4) Seconds
so there is no article_id being read into the query, but i cant see why this is? :s can anyone help?
Thanks,
Sunny