AlexGM16 Posted November 23, 2006 Share Posted November 23, 2006 i have a page called managenews.php, which displays all the news articles I have written, with a 'delete' and 'edit' link next to them. Well the delete page works perfectly fine, but when I click edit I get the default Internal server error.The query works just fine when i insert some dummy info into it via phpmyadmin.[b]editnews.php[/b][code]<?phpif($_POST['submit']) {$title = $_POST['title'];$newstext = $_POST['newstext']; $db=mysql_connect("localhost", "user", "pass") or die("Could not connect to localhost"); mysql_select_db("alex", $db) or die("Could not find database alex");$querySQL = mysql_query("UPDATE news SET postdate='CURDATE()', title='".$title."', newstext='".$newstext."' WHERE id='".$id."'") or die(mysql_error());header("Location: managenews.php");} else {$id = $_GET['id'];$db=mysql_connect("localhost", "user", "pass") or die("Could not connect to localhost"); mysql_select_db("alex", $db) or die("Could not find database alex");$query = mysql_query("SELECT * FROM news WHERE id='".$id."'");while($results = mysql_fetch_assoc($query)) {?><form name="editNews" method="post"action="<? $_SERVER['PHP_SELF']; ?>"><?echo "<input type=\"text\" name=\"title\" size=\"20\" value=\"{$results['title']}\" /><br />";echo "<input type=\"text\" name=\"newstext\" size=\"20\" value=\"{$results['newstext']}\" />";}?><input type="submit" name="submit" value="submit" /></form><? } ?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/28247-editing-records-with-form/ Share on other sites More sharing options...
HuggieBear Posted November 23, 2006 Share Posted November 23, 2006 This can't be all the code as there's no buttons for Update and Delete here.Are you able to provide all the relevant code for that page?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/28247-editing-records-with-form/#findComment-129190 Share on other sites More sharing options...
Philip Posted November 23, 2006 Share Posted November 23, 2006 [quote]Well the delete page works perfectly fine, but when I click edit I get the default Internal server error.[/quote]Please post the code where you have the link to the edit page. Quote Link to comment https://forums.phpfreaks.com/topic/28247-editing-records-with-form/#findComment-129195 Share on other sites More sharing options...
AlexGM16 Posted November 23, 2006 Author Share Posted November 23, 2006 sry guys:[b]managenews.php[/b][code]<?phpinclude "displayNewsEdit.inc"; /* user config variables */$max_items = 5; /* max number of news items to show */$db = mysql_connect ('localhost','user','pass');mysql_select_db ('alex',$db);echo "<center>\n";displayNews();echo"</center>\n";?>[/code][b]displayNewsEdit.inc[/b][code]<?phpfunction displayNews($all = 0) { global $db, $max_items; if ($all == 0) { $query = "SELECT id,title,newstext," . "DATE_FORMAT(postdate, '%M %D, %Y') as date " . "FROM news ORDER BY postdate DESC LIMIT $max_items"; } else { $query = "SELECT id,title,newstext," . "DATE_FORMAT(postdate, '%M %D, %Y') as date " . "FROM news ORDER BY postdate DESC"; } $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { echo "<TABLE border=\"1\" width=\"320\">\n"; $date = $row['date']; $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); echo "<TR><TD><b>$title</b> posted on $date <a href=\"delete.php?id={$row['id']}\">Delete</a> | <a href=\"edit.php?id={$row['id']}\">Edit</a></TD></TR>\n"; echo "<TR><TD>$news</TD></TR>\n"; echo "</TABLE>\n";echo "<BR>\n";} /* if we aren't displaying all news, * then give a link to do so */ /* taking out the view all news link for now****************************** if ($all == 0) { echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=all\">View all news</a>\n"; } *********************************/}?>[/code][b]delete.php[/b][code]<?php$db=mysql_connect("localhost", "user", "pass") or die("Could not connect to localhost."); mysql_select_db("alex", $db) or die("Could not find database alex");/* get id from url */$id = $_GET['id'];/* delete record */$sql = "DELETE FROM news WHERE id=".$id;$result = mysql_query( $sql ) or die( mysql_error() );/* redirect user back to edit news page */header("Location: managenews.php");?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/28247-editing-records-with-form/#findComment-129220 Share on other sites More sharing options...
AlexGM16 Posted November 24, 2006 Author Share Posted November 24, 2006 *bump* code updated still get internal server error Quote Link to comment https://forums.phpfreaks.com/topic/28247-editing-records-with-form/#findComment-129612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.