MoFish Posted June 4, 2006 Share Posted June 4, 2006 Hello everyone.Im currently in the process of making an edit news script, which is semi working until I click the edit button then it simply doesnt update anything. I cant see where im going wrong with it, so was hoping someone with php eyes could spot where ive gone horribly wrong.table name: newsfield names:news_idnews_namenews_infonews_postedby.the script displays the newly added news fine, it then loads the correct information into the boxes to be edited. when i click the edit button however nothing updates and i get the message Thank you! Information updated when it actually didnt update at all :(thanks again, mofishthis block works[code]<? if(!isset($cmd)) { $result = mysql_query("select * from news order by news_id"); while($r=mysql_fetch_array($result)) { $title=$r["news_name"]; $id=$r["news_id"]; echo "<a href='index.php?page=editnews&cmd=edit&news_id=$id'>$title - Edit</a>"; echo "<br>"; }}?>[/code]this block works[code]<?if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit"){ if (!isset($_POST["submit"])) { $id = $_GET["news_id"]; $sql = "SELECT * FROM news WHERE news_id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result);?> <form action="index.php?page=editnews" method="post"> <input type=hidden name="news_id" value="<?php echo $myrow["news_id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="news_name" VALUE="<?php echo $myrow["news_name"] ?>" SIZE=30><br> Message:<TEXTAREA NAME="news_info" ROWS=10 COLS=30><? echo $myrow["news_info"] ?></TEXTAREA><br> Who:<INPUT TYPE="TEXT" NAME="news_postedby" VALUE="<?php echo $myrow["news_postedby"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?>[/code][!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--][b]this block doesnt appear to work.[/b][!--colorc--][/span][!--/colorc--][code]<? if ($_POST["$submit"]) { $title = $_POST["news_name"]; $message = $_POST["news_info"]; $who = $_POST["news_postedby"]; $sql = "UPDATE news SET news_name='$title',news_info='$message',news_postedby='$who' WHERE news_id=$id"; $result = mysql_query($sql); echo "Thank you! Information updated."; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11196-edit-news-script/ Share on other sites More sharing options...
trq Posted June 4, 2006 Share Posted June 4, 2006 You should always test to see if your query actually works before displaying a success message. Try...[code]if ($result = mysql_query($sql)) { echo "Thank you! Information updated.";} else { die(mysql_error()." sql = ".$sql);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11196-edit-news-script/#findComment-41883 Share on other sites More sharing options...
MoFish Posted June 4, 2006 Author Share Posted June 4, 2006 perfect that lead me to find the problem. all working good now. thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/11196-edit-news-script/#findComment-41885 Share on other sites More sharing options...
redarrow Posted June 4, 2006 Share Posted June 4, 2006 Try this your using 2 named sql querys.[code]<? if ($_POST["$submit"]) { $title = $_POST["news_name"]; $message = $_POST["news_info"]; $who = $_POST["news_postedby"]; $sql2 = "UPDATE news SET news_name='$title',news_info='$message',news_postedby='$who' WHERE news_id=$id"; $result = mysql_query($sql2); echo "Thank you! Information updated."; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11196-edit-news-script/#findComment-41886 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.