Perad Posted October 28, 2006 Share Posted October 28, 2006 Everything works apart from the final edit part. I keep getting "you cocked up" which the message when it fails. Could someone help me determine why this fails.[code=php:0]<php function editNews($id) { global $dbc; $query = "SELECT * FROM news WHERE id=$id"; $result = mysql_query ($query); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Invalid News ID\n"; return; } $row = mysql_fetch_assoc($result); echo "<TABLE border=\"1\" width=\"580\">\n"; /* easier to read variables and * striping out tags */ $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); /* display the items */ echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=handleedit&id=$id\" method=POST>\n"; echo "<input type=\"text\" name=\"newstitle\" value = \"".$title."\" size=\"50\" maxlength=\"50\" /><br />"; echo "<TEXTAREA cols=\"60\" rows=\"12\" " . "name=\"content\">$news</TEXTAREA><BR>\n"; echo "<input type=\"submit\" name=\"editsubmit\" " . "value=\"Save Changes\"\n"; echo "</FORM>\n"; } function handleEdit($id) { global $dbc; $t = $_POST['newstitle']; $c = $_POST['content']; $query = "UPDATE news SET title='$t' newstext='$c' WHERE id='$id'" OR die ('Could not connect to MySQL: ' . mysql_error() ); $result = mysql_query($query); if ($result) { // If it ran OK. // Confirmation. echo '<p><b>The news article has been added successfully!</b></p>'; } else { echo 'You cocked it up'; } exit(); // Quit the script. mysql_close(); // Close the database connection. } /* this is where the script decides what do do */ if ($IsLoggedIn == 1) { echo "<CENTER>\n"; switch($_GET['action']) { case 'handleedit': handleEdit($_GET['id']); break; case 'edit': editNews($_GET['id']); break; case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayNews(); } }?>[/code] Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 28, 2006 Share Posted October 28, 2006 Try changing this:[code]$query = "UPDATE news SET title='$t' newstext='$c' WHERE id='$id'" OR die ('Could not connect to MySQL: ' . mysql_error() );$result = mysql_query($query);[/code]To this:[code]$query = "UPDATE news SET title='".$t."' newstext='".$c."' WHERE id='".$id."'";$result = mysql_query($query) or die ('Could not connect to MySQL: ' . mysql_error() );[/code] Quote Link to comment 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.