Jump to content


unable to edit existing sql data

  • Please log in to reply
No replies to this topic

#1 gillms1

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 April 2006 - 09:08 PM

Hi, I have the following code which displays all articles in my database (editarticlelist.php) ;
include "admin_header.php";
include "db_connect.php";

// Open DB and init cutoff
$link = opendb();

// Get all article titles in timeframe and that are published
$query = "SELECT * FROM articles";
$result = mysql_query($query,$link)
or die("Query failed: $query");

echo "<h3>Please select article to edit</h3><p>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

<b><a href="editarticle2.php?article_id=$line[article_id]">
$line[headline] </b>
<i>created by: <b>$line[editor]</b>
&nbsp category: <b>$line[section]</b>
&nbsp published on: $line[created]<p>


} // End while



and then i have the following code (editarticle.php) which the user is transferred to once they click on a headline (i want them to be able to edit the data and then update in my sql table) :


include "admin_header.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>');


$article_id = $_GET['article_id'];
$headline = $_POST['headline'];
$subheadline = $_POST['subheadline'];
$content = $_POST['content'];

$sql = mysql_query("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 "<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=index.php>";

$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"];
<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: <input name="headline" size="40" maxlength="255" value="<? echo $headline; ?>">
subheadline: <textarea name="subheadline" rows="7" cols="30"><? echo $subheadline; ?></textarea>
content: <textarea name="content" rows="7" cols="30"><? echo $content; ?></textarea>
<input type="submit" name="submit" value="Update News">
<?php } ?>
<?php include('admin_footer.php'); ?>

the problem is that the user is transferred to the forms page, but the data doesnt appear in the text boxes, instead it appears as :

<? echo $headline; ?> in the headline box.
<? echo $subheadline; ?> in the subheadline box.
<? echo $content; ?> in the content box.

can anyone help me with a way so that the data stored that particular article_id appears in the boxes for editing?



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users