Hi there,
I’m working on a kind of news script. Now I have a piece of code. It works untill it has to change something in the database. The script has to update a record, it confirms that it has but it doesn’t change the record. I don’t understand why, can someone take a look at my code?
<?
include("connectie.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from vinnieb2_cms 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
$id=$r["id"];
$titel=$r["titel"];
$content=$r["content"];
echo "<table border='1'>";
echo "<tr> <th>id</th><th>titel</th><th>content</th></tr>";
// keeps getting the next row until there are no more to get
while($r = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<a href='edit2.php?cmd=edit&id=$id'>$id - Edit</a>";
echo "<br>";
echo "</td><td>";
echo $r['titel'];
echo "<br>";
echo "</td><td>";
echo $r['content'];
echo "</td></tr>";
}
echo "</table>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM vinnieb2_cms WHERE id=$id";
$result = mysql_query($sql);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
titel:<INPUT TYPE="TEXT" NAME="titel" VALUE="<?php echo $myrow["titel"] ?>" SIZE=30><br>
content:<INPUT TYPE="TEXT" NAME="tekst" VALUE="<?php echo $myrow["content"] ?>" SIZE=30><br>
<br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$id = $_POST["id"];
$titel = $_POST["titel"];
$content = $_POST["content"];
$sql = "UPDATE vinnieb2_cms SET titel='$titel',content='$content' WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>