Nieuw lid |
|
Hallo allemaal,
Ik heb hier een script edit.php:
<?
//connect to mysql
mysql_connect("localhost","database","password");
//select database
mysql_select_db("database");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$title=$r["title"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news 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"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$title = $_POST["title"];
$message = $_POST["message"];
$who = $_POST["who"];
$sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
<? //connect to mysql //select database //If cmd has not been initialized { //display all the news $result = mysql_query("select * from news order by id"); //run the while loop that grabs all the news scripts { //grab the title and the ID of the news $title=$r["title"];//take out the title $id=$r["id"];//take out the id //make the title a link echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>"; } } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM news WHERE id=$id"; ?> <form action="edit.php" method="post"> <input type=hidden name="id" value=" <?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE=" <?php echo $myrow["title"] ?>" SIZE=30><br> Message:<TEXTAREA NAME="message" ROWS=10 COLS=30> <? echo $myrow["message"] ?></TEXTAREA><br> Who:<INPUT TYPE="TEXT" NAME="who" VALUE=" <?php echo $myrow["who"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $title = $_POST["title"]; $message = $_POST["message"]; $who = $_POST["who"]; $sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id"; echo "Thank you! Information updated."; } } ?>
Het laatste deel van het script wordt niet uitgevoerd. Er zitten gegevens in de database en alles werkt maar zodra ik iets aanpas en verzend krijg ik geen foutmelding maar gewoon weer de titel van het nieuws te zien waarop ik ook weer kan klikken om het aan te passen. Hij update niet en ik krijg ook geen melding "Thank you! Information updated."
|