rmt99e Posted July 29, 2008 Share Posted July 29, 2008 hey guys, im making a news feed in php - i'm working on the edit page. everything works okay except it doesn't actually update the news in the DB .. Thanks <?php include("config.php"); if(isset($_POST['submit'])) { $title = mysql_escape_string($_POST['title']); $text1 = mysql_escape_string($_POST['text1']); $result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect); echo "News updated successfully. Redirecting..."; echo "<meta http-equiv=Refresh content=2;url=view_news.php>"; } elseif(isset($_GET['newsid'])) { $result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]'", $connect); while($myrow = mysql_fetch_assoc($result)) { $title = $myrow["title"]; $text1 = $myrow["text1"]; ?> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>"> Title<br> <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"> <br>Text<br> <textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea> <br><br> <input type="submit" name="submit" value="Update News"> </form> <? }//end of while loop }//end of else ?> Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/ Share on other sites More sharing options...
DarkWater Posted July 29, 2008 Share Posted July 29, 2008 Change: $result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect); To: $result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect) or die(mysql_error()); Tell us what it says after that. Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602744 Share on other sites More sharing options...
revraz Posted July 29, 2008 Share Posted July 29, 2008 I don't see where you set $newsid Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602756 Share on other sites More sharing options...
DarkWater Posted July 29, 2008 Share Posted July 29, 2008 Me either, which is what I suspect the problem is. I just wanted to verify. Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602763 Share on other sites More sharing options...
TempleDMDKrazd Posted July 29, 2008 Share Posted July 29, 2008 the problem lies further than what is shown in the code in his form he has the following: <input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>"> that assumes that $myrow['newsid'] actually has a value or does it? i bet you the problem is there... Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602799 Share on other sites More sharing options...
revraz Posted July 29, 2008 Share Posted July 29, 2008 He never sets $newsid from the input name newsid. Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602805 Share on other sites More sharing options...
rmt99e Posted July 29, 2008 Author Share Posted July 29, 2008 Got it. I added $newsid = $_GET['newsid']; at the top. <?php include("config.php"); if(isset($_POST['submit'])) { $title = mysql_escape_string($_POST['title']); $text1 = mysql_escape_string($_POST['text1']); $newsid = $_GET['newsid']; $result = mysql_query("UPDATE news SET title='$title', text1='$text1' WHERE newsid='$newsid'",$connect) or die(mysql_error()); echo "News updated successfully. Redirecting..."; echo "<meta http-equiv=Refresh content=2;url=view_news.php>"; } elseif(isset($_GET['newsid'])) { $result = mysql_query("SELECT * FROM news WHERE newsid='$_GET[newsid]'", $connect); while($myrow = mysql_fetch_assoc($result)) { $title = $myrow["title"]; $text1 = $myrow["text1"]; ?> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="newsid" value="<? echo $myrow['newsid'] ?>"> Title<br> <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"> <br>Text<br> <textarea name="text1" rows="7" cols="30"><? echo $text1; ?></textarea> <br><br> <input type="submit" name="submit" value="Update News"> </form> <? }//end of while loop }//end of else ?> Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602881 Share on other sites More sharing options...
revraz Posted July 29, 2008 Share Posted July 29, 2008 Marked as solved please. Quote Link to comment https://forums.phpfreaks.com/topic/117184-query-help/#findComment-602988 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.