Opdatere data i MYSQL via php
HejJeg får følgende:
Notice: Undefined index: cmd in c:\program files\easyphp1-7\www\mitsite\edit.php on line 29
hvilket er if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
<?
include 'connect.php';
//select which database you want to edit
mysql_select_db("db");
//If cmd has not been initialized
if(!isset($cmd))
{
$result = mysql_query("select * from bestilling_tbl order by bestillingsdato");
//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
$bestillingsdato=$r["bestillingsdato"];
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='edit.php ?cmd=edit&id=$id'>$bestillingsdato - Rediger</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM bestilling_tbl 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"] ?>">
Bestillingsdato:<INPUT TYPE="TEXT" NAME="bestillingsdato" VALUE="<?php echo $myrow["bestillingsdato"] ?>" SIZE=30><br>
Leverandør:<input type="text" NAME="leverandoer" value="<? echo $myrow["leverandoer"] ?>" size=30<br>
<br>Pris:<INPUT TYPE="TEXT" NAME="pris" VALUE="<?php echo $myrow["pris"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["submit"])//if ($_POST["$submit"])
{
$bestillingsdato = $_POST["bestillingsdato"];//bestillingsdato
$leverandoer = $_POST["leverandoer"];//
$pris = $_POST["pris"];
$sql = "UPDATE bestilling_tbl SET bestillingsdato='$bestillingsdato',leverandoer='$leverandoer',pris='$pris' WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Så er den opdateret";
}
}
?>
