Jump to content

Archived

This topic is now archived and is closed to further replies.

MoFish

Edit News Script

Recommended Posts

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

[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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
perfect that lead me to find the problem. all working good now. thanks alot

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.