med forbehold for fejl:
<?php
include("../config.php");
if(isset($_POST['submit2'])){
$res=mysql_query("SELECT nyhed,overskrift,dato,klok FROM nyhed WHERE id='".$_POST['oid']."'");
list($nyhed,$overskrift,$dato,$klok)=mysql_fetch_row($res);
}elseif(isset($_POST['submit'])){
$id = $_POST['pId'];
$overskrift = $_POST['overskrift'];
$nyhed = $_POST['nyhed'];
$dato = $_POST['dato'];
$klok = $_POST['klok'];
mysql_query("update nyhed set overskrift = '".$overskrift."', nyhed='".$nyhed."', dato='".$dato."', klok='".$klok."' where id=$id");
$msg = "Nyheden blev opdateret";
}else{
$res = mysql_query("SELECT id,overskrift,nyhed,dato,klok FROM nyhed ORDER BY id DESC LIMIT 1");
list($id,$overskrift,$nyhed,$dato,$klok)=mysql_fetch_row($res);
}
$sql = mysql_query("SELECT id,overskrift FROM nyhed");
$nopts="";
while($row=mysql_fetch_array($sql)){
$nopts.='<option value="'.$row['id'].'">'.$row['overskrift'];
}
$udskriv = mysql_fetch_array($sql);
?>
Vælg nyhed:
<form action="" method="post">
<select name="oid"><?php echo $nopts;?></select>
<input style="width:70px; height:20px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF" value="Vælg Nyhed" name="submit2" type="submit" />
</form>
<br /><br />
<form action="" method="post">
overskrift:<br />
<input type="text" value="<?php echo $overskrift; ?>" name="overskrift" style="width:300px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF" /><br /><br />
nyhed:<br />
<textarea name="nyhed" style="height:200px; width:300px; margin-top:2px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF">
<?php echo $nyhed; ?>
</textarea>
<br /><br />
dato:<br />
<input type="text" value="<?php echo $dato; ?>" name="dato" style="width:180px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF" /><br />
klok<br />
<input type="text" value="<?php echo $klok; ?>" name="klok" style="width:180px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF" />
<br /><br />
<input type="hidden" name="pId" value="<?php echo $id; ?>">
<input style="width:70px; color: #666666; font-size: 8pt; border: 1px solid #C0C0C0; padding: 2px; background-color:#FFFFFF" value="Ret Profil" name="submit" type="submit" />
</form>
<br />
<?php
echo $msg;
echo "<br />";
?>