Jump to content

unable to edit existing sql data


gillms1

Recommended Posts

Hi, I have the following code which displays all articles in my database (editarticlelist.php) ;
<?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)) {


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

HTML;

} // End while

mysql_close($link);
include('admin_footer.php');


?>

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) :

<?php

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>');
}

if(isset($_POST['submit']))
{

$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>";
}
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: <input name="headline" size="40" maxlength="255" value="<? echo $headline; ?>">
<br>
subheadline: <textarea name="subheadline" rows="7" cols="30"><? echo $subheadline; ?></textarea>
<br>
content: <textarea name="content" rows="7" cols="30"><? echo $content; ?></textarea>
<br>
<input type="submit" name="submit" value="Update News">
</form>
<?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?

thanks,

Sunny
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.