gillms1 Posted April 22, 2006 Share Posted April 22, 2006 Hi, I have the following code which displays all articles in my database (editarticlelist.php) ;<?phpinclude "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>   category: <b>$line[section]</b>   published on: $line[created]<p>HTML;} // End whilemysql_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 https://forums.phpfreaks.com/topic/8134-unable-to-edit-existing-sql-data/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.