-1

Hello!

I have been trying to make a news script where you can edit/delete news. I've looked for tutorials and tried to make mine too. But I still have some problems, and I don't know what is wrong.

So, I'm posting the code here, maybe someone can help me.

<?php 
include("db.php");

if(!isset($cmd)) 
{
   $result = mysql_query("select * from xuudis_uudis order by id"); 
   
   while($r=mysql_fetch_array($result)) 
   { 
      $title=$r["uudis_pealkiri"];
      $id=$r["id"];
     
      echo "<a href='edit.php?cmd=edit&id=$id'>$title - Muuda!</a>";
      echo "<br>";
    }
}
?>
<br />
<br />
<br />
<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM xuudis_uudis WHERE id=$id";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
	  
      <form action="edit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
   
      Pealkiri: <INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["uudis_pealkiri"] ?>" SIZE=40><br /><br />
      Kuupäev: <INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["uudis_kuu"] ?>" SIZE=30><br><br />
	  Uudis: <TEXTAREA NAME="message" ROWS=5 COLS=55><?php echo $myrow["uudis_uudis"] ?></TEXTAREA><br><br />
    
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="Muuda!">
   
      </form>
   
<?php } ?>

<?php
   if ($_POST["$submit"])
   {
      $title = $_POST["title"];
	  $message = $_POST["message"];
	  $who = $_POST["who"];
	  
	  $sql = "UPDATE xuudis_uudis SET uudis_pealkiri='$title', uudis_uudis='$message', uudis_kuu='$who' WHERE id=$id";
	  
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
	}
}
?>

The mysql table's name is xuudis_uudis.

Im trying to make a script where you can edit news.
I want that you could edit Title [uudis_pealkiri]
Date[uudis_kuu]
Content[uudis_uudis]

Everything works, it connects to the database.
Gets the information.

But when I edit the text and 'submit' it, it does nothing.
So, I am a bit confused.

Thanks,

Taavi

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Taavi
-1
//pLS CHANGE 
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") 

//to 

if($_REQUEST["cmd"]=="edit")

Edited by hakimkal: n/a

-1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

      <div align="center">
  <?php 
include("db.php");

if(!isset($cmd)) 
{
   $result = mysql_query("select * from xuudis_uudis order by id"); 
   
   while($r=mysql_fetch_array($result)) 
   { 
      $title=$r["uudis_pealkiri"];
      $id=$r["id"];
     
      echo "<a href='edit.php?cmd=edit&id=$id'>$title - Muuda!</a>";
      echo "<br>";
    }
}
?>
  <br />
  <br />
  <br />
  <?php
if($_REQUEST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM xuudis_uudis WHERE id=$id";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
        
      </div>
      <form action="edit.php" method="post">
        <div align="center">
        <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
   
      Pealkiri: 
      <INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["uudis_pealkiri"] ?>" SIZE=40>
      <br />
      <br />
      Kuupäev:
      <INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["uudis_kuu"] ?>" SIZE=30>
      <br>
      <br />
	  Uudis: 
	  <TEXTAREA NAME="message" ROWS=5 COLS=55><?php echo $myrow["uudis_uudis"] ?></TEXTAREA>
	  <br>
	  <br />
    
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="Muuda!">
   
        </div>
      </form>
   
      <div align="center">
  <?php } ?>
        
  <?php
if (isset($_POST['submit']))
      $title = $_POST["title"];
	  $message = $_POST["message"];
	  $who = $_POST["who"];
	  
	  $sql = "UPDATE xuudis_uudis SET uudis_pealkiri='$title', uudis_uudis='$message', uudis_kuu='$who' WHERE id=$id";
	  
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
	}
?>
        
        
        
      </div>
</body>
</html>

Thanks for the help, but there is still some problems.

1. The 'Thank you! Information updated. ' - just comes there, if I open the page.

2. If I edit one news content other go blank.

Taavi

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.