Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/11196-edit-news-script/
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]
Link to comment
https://forums.phpfreaks.com/topic/11196-edit-news-script/#findComment-41886
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.