Jump to content


Photo

Edit News Script


  • Please log in to reply
3 replies to this topic

#1 MoFish

MoFish
  • Members
  • PipPipPip
  • Advanced Member
  • 210 posts

Posted 04 June 2006 - 10:37 PM

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:

news

field names:

news_id
news_name
news_info
news_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, mofish

this block works

<? 
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>";
    }
}
?>

this block works

<?
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>
   
<? 
} 
?>

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]this block doesnt appear to work.[!--colorc--][/span][!--/colorc--]

<?
   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.";
    }
}
?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 June 2006 - 10:48 PM

You should always test to see if your query actually works before displaying a success message. Try...
if ($result = mysql_query($sql)) {
    echo "Thank you! Information updated.";
} else {
    die(mysql_error()." sql = ".$sql);
}


#3 MoFish

MoFish
  • Members
  • PipPipPip
  • Advanced Member
  • 210 posts

Posted 04 June 2006 - 10:58 PM

perfect that lead me to find the problem. all working good now. thanks alot

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 June 2006 - 10:59 PM

Try this your using 2 named sql querys.



<?
   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.";
    }
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users