Steppio Posted March 26, 2007 Share Posted March 26, 2007 I have a small problem with regards to one of my last posts, i have an edit link below every news article, and that link goes to a page where the title and it's article are then displayed in a input box and a textarea respectively. The only problem is it's coming back that it was succesful, but the contents don't change. The code for the page is as follows: <?php require_once('main_fns.php'); $head=$_POST['up_head']; $news=$_POST['up_news']; $id=$_POST['up_id']; session_start(); try { //check forms filled in if (!filled_out($_POST)) { throw new Exception('You have not filled out the form correctly '. '- please go back and try again.'); } // attempt to update // this function can also throw an exception updatenews($head, $news, $id); // provide link to members page require('head.inc'); echo $news; echo 'The update was succesful. '; echo '<a href="main.php?<?php echo strip_tags(SID); ?>">Back to main page</a>'; require('foot.inc'); } catch (Exception $e) { require('head.inc'); echo $e->getMessage(); require('foot.inc'); exit; } ?> and the code for the function is as follows: function updatenews($head, $news, $id) { $conn = db_connect(); $result = $conn->query( "update news set newshead = '$head', news='$news' where id = '$id'"); if (!$result) throw new Exception('Could not change password.'); } and the function that passes the variables from the editing page is: function edit_news($id) { mysql_conn1(); $result2 = @mysql_query("SELECT id, newshead, news FROM news WHERE id='$id'"); if (!$result2) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row2 = mysql_fetch_array($result2)) { $id = $row2['id']; $head = $row2['newshead']; $news = $row2['news']; } ?> <table><tr><td> <form class="AddNews" method="post" action="updatenews.php"> <br><center> Add an article: <br> ID: <input disabled="disabled" type="text" class="sub1" name="up_id" size="3" value="<?php echo $id;?>"<br> Title: <input type="text" class="sub1" name="up_head" size="40" value="<?php echo $head;?>"<br> Content: <textarea cols="250" rows="40" class="sub1" name="up_news"><?php echo $news;?></textarea><br> <input type="submit" class="sub" value="Update"><br /> </form></td></tr> </table> <?php } Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/ Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 [ code ][ /code ] Please! Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-215761 Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 Try this function updatenews($head, $news, $id) { $conn = db_connect(); $conn->query( "update news set newshead = '$head', news='$news' where id = '$id'") OR throw new Exception('Could not change password. ' . mysql_error()); } See where that gets you. Also I would look into the mysql_real_escape_string to clean variables for entry into mysql. Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-216098 Share on other sites More sharing options...
Steppio Posted March 31, 2007 Author Share Posted March 31, 2007 The code still isnt working, i'm thinking it's probably a problem in seperating the variables so that the 'new' news article is being ignored by the 'old' article. I'm thinking i can maybe try it on a smaller project and try and get it working there, and then maybe introduce it to this project. There must be another way around it. Any ideas? Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-218667 Share on other sites More sharing options...
Steppio Posted April 1, 2007 Author Share Posted April 1, 2007 Can anybody help me with this please? Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-219405 Share on other sites More sharing options...
Steppio Posted April 2, 2007 Author Share Posted April 2, 2007 Sorted. Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-219472 Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 well looking at what you posted, there is something wrong with this section. maybe you can see it echo 'The update was succesful. '; echo '<a href="main.php?<?php echo strip_tags(SID); ?>">Back to main page</a>'; require('foot.inc'); Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-219474 Share on other sites More sharing options...
Steppio Posted April 2, 2007 Author Share Posted April 2, 2007 The url bit? Thats not part of the code, for some reason when i added that line the forum form changed it to that :/ Link to comment https://forums.phpfreaks.com/topic/44429-solved-updating-database-problems/#findComment-219492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.