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