Forum Moderators: coopster

Message Too Old, No Replies

Retrieve values to display in the form

         

EfEnrico

9:52 am on Jun 11, 2004 (gmt 0)

10+ Year Member



Hey all,

Here is the question. I have news items stored in my database with id, titel, content and date). I made the below script to edit the news. The script works.. only when I select a news item, the titel and content are not shown.. this is very unhandy when you only want to correct a typo!

What am I doing wrong?

THnx for any help.

<?php

if ($_POST['submit']){
include ("dbconnect.php");

if (($_POST['titel_nieuw'] == "") OR ($_POST['bericht_nieuw'] == "")) {
echo ("Je hebt niet alle velden ingevuld!<br><br>");
} else {

// Maak query om gegevens in tabel te stoppen
$titel_nieuw = $_POST['titel_nieuw'];
$bericht_nieuw = $_POST['bericht_nieuw'];
$select = $_POST['select'];
$query = "UPDATE nieuws SET titel='$titel_nieuw', bericht='$bericht_nieuw' WHERE id='$select'";
mysql_query($query) or die ("query mislukt");
echo ("Het nieuwsbericht is succesvol aangepast!");
}

}else{

?>
<FORM ACTION="<?=$_SERVER['PHP_SELF']?>" METHOD="post">
<INPUT TYPE="hidden" NAME="submit" VALUE="geen">
Kies een nieuwsbericht:<br><SELECT NAME="select">
<?php
include ("dbconnect.php");

$today = mktime(date("H"),date("i"),0,date("m"),date("d"),date("Y"));
$query = "SELECT * FROM nieuws WHERE datum <= ' " . $today . " ' ORDER BY -datum";
$resultaat = mysql_query($query) or die ("Ivm problemen met de database zijn de nieuwsmededelingen momenteel niet beschikbaar");
$NLmaand = array("", "jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sept", "okt", "nov", "dec");
while($data = mysql_fetch_object($resultaat)){
$titel = "$data->titel";
$bericht = "$data->bericht";
$dag = date("j", $data->datum);
$maand = date("n", $data->datum);
$id = "$data->id";
?>
<OPTION VALUE="<? echo "$id";?>"><?php echo $dag . " " . $NLmaand[$maand];?>: <? echo "$titel";?></OPTION>
<?
}
?>
</SELECT><br><br>

Titel:<br>

<INPUT NAME="titel_nieuw" TYPE="text" SIZE="55" VALUE="<? echo "$titel";?>"><br><br>

Bericht:<br>
<TEXTAREA NAME="bericht_nieuw" COLS="50" ROWS="6"><? echo "$bericht";?></textarea><br><br>

<INPUT TYPE="submit" VALUE="Bewerk het bericht">
</FORM>
<?
}
?>

coopster

10:16 am on Jun 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't see where you are retrieving the title's data when you select an item upon posting the form...?