jeg ved ikke om man stadig kan se det gamle indlæg, så prøver igen. Jeg var heldig at få hjælp at to til at lave en listbox som henter værdierne fra en database.
Jeg valgte at bruge dette script, da jeg bedst kunne finde ud af det...
echo "<select>";
$res = mysql_query( "SELECT id,produktnavn from produkter" );
if ($res)
{
$nr = mysql_num_rows( $res );
$i = 0;
while ( $i< $nr )
{
$navn = mysql_result( $res , $i , "produktnavn");
$id = mysql_result( $res , $i , "id" );
echo "<option value=\\"".$id."\\">".$navn."</option>";
$i++;
}
}
echo "</select>";
Jeg skal gerne have dette bygget sammen med min formular som virker pånær denne listbox. man skal kunne vælge produkt i listboxen, og så markere dette, hvorefter den værdi der er markeret sendes sammen med de andre værdier til databasen.
herunder har jeg koden for formularen, hvor denne listbox gerne skulle bygges ind, samt den side, der modtager informationerne og sætter disse i databasen.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>HBK opret formands nyhed</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body { font-family: Arial; font-size: 10pt; background-color: #eeeeee; }
td { font-family: Arial; font-size: 10pt; }
a { text-decoration: none; color: #777777; }
a:visited { text-decoration: none; color: #777777; }
a:active { text-decoration: none; color: #777777; }
a:hover { text-decoration: underline; color: #000000; }
</style>
</head>
<body>
<form name="form1" method="post" action="uploadformand.php" enctype=multipart/form-data>
<p> <b></b></p>
<table width="100%" border="0" style="border: 1px solid #005991;">
<tr>
<td bgcolor="#bfe0fe"><b><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Oprettelse
af Formands nyheder på www.hbkbadminton.dk</font></b></td>
</tr>
</table>
<table width="100%" border="0" bgcolor="#F5FAFF">
<tr>
<td bgcolor="#f5faff"><p><b><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="cms.php">Retur
Uden Oprettelse af formands nyheder</a></font></b></p>
<table width="100%" border="0" style="border: 1px solid #005991;">
<tr>
<td width="26%" bgcolor="#f5faff"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Overskrift
</b> <b><i>(overskrift på nyheden)</i></b></font></td>
<td bgcolor="#f5faff"><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">
<input name="overskrift" type="text" id="overskrift">
</font></td>
</tr>
<tr>
<td bgcolor="#f5faff"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Nyhed</b></font></td>
<td bgcolor="#f5faff" ><textarea name="nyhed" wrap="virtual" cols="50" rows="10"></textarea></td>
</tr>
</table></td>
</tr>
</table>
<p>
<input type=file name=img value=news.jpg size=30 id="img">
<br>
<input type="hidden" name="submitted" value="true">
<input type="submit" name="submit" value="Upload">
</p>
<p>
</p>
<p><b><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><i>Vælg et billede til nyheden</i></font></b></p>
</form>
</body>
</html>
samt den side der modtager
<?
$db="";
$link=mysql_connect("");
if(!$link)
die ("kan ikke connecte");
mysql_select_db($db,$link)
or die ("kan ikke aabne database");
$query=("insert into hbkformand(overskrift,nyhed,img_name) values ('$overskrift','$nyhed','$img_name')");
mysql_query($query,$link);
?>
<?
//user defined variables
$abpath = ""; //Absolute path to where images are uploaded. No trailing slash
$sizelim = "no"; //Do you want size limit, yes or no
$size = "92500000"; //What do you want size limited to be if there is one
$number_of_uploads = 1; //Number of uploads to occur
if ($_REQUEST['submitted']){ // Begin processing portion of script
//all image types to upload
$cert1 = "image/pjpeg"; //Jpeg type 1
$cert2 = "image/jpeg"; //Jpeg type 2
$cert3 = "image/gif"; //Gif type
$cert4 = "image/ief"; //Ief type
$cert5 = "image/png"; //Png type
$cert6 = "image/tiff"; //Tiff type
$cert7 = "image/bmp"; //Bmp Type
$cert8 = "image/vnd.wap.wbmp"; //Wbmp type
$cert9 = "image/x-cmu-raster"; //Ras type
$cert10 = "image/x-x-portable-anymap"; //Pnm type
$cert11 = "image/x-portable-bitmap"; //Pbm type
$cert12 = "image/x-portable-graymap"; //Pgm type
$cert13 = "image/x-portable-pixmap"; //Ppm type
$cert14 = "image/x-rgb"; //Rgb type
$cert15 = "image/x-xbitmap"; //Xbm type
$cert16 = "image/x-xpixmap"; //Xpm type
$cert17 = "image/x-xwindowdump"; //Xwd type
$log = "";
//checks if file exists
if ($img_name == "") {
$log .= "No file selected for upload $i<br>";
}
if ($img_name != "") {
//checks if file exists
if (file_exists("$abpath/$img_name")) {
$log .= "Filen $i ligger allerede på serveren<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img_size > $size)) {
$log .= "File $i was too big<br>";
} else {
//Checks if file is an image
if (($img_type == $cert1) or ($img_type == $cert2) or ($img_type == $cert3) or ($img_type == $cert4) or ($img_type == $cert5) or ($img_type == $cert6) or ($img_type == $cert7) or ($img_type == $cert8) or ($img_type == $cert9) or ($img_type == $cert10) or ($img_type == $cert11) or ($img_type == $cert12) or ($img_type == $cert13) or ($img_type == $cert14) or ($img_type == $cert15) or ($img_type == $cert16) or ($img_type == $cert17)) {
@copy($img, "$abpath/$img_name") or $log .= "Kunne ikke uploade billedet til serveren<br>";
if (file_exists("$abpath/$img_name")) {
$log .= "Filen $i er uploadet til serveren<br>";
}
} else {
$log .= "Det $i er ikke en billedefil, upload kun billedefiler som jpg, gif filer<br>";
}
}
}
}
?>
</p>
<p><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>Resultats meddelse:</b></font>:<br>
<?
echo "$log";
?><br>
</p>
<?
exit;
} // End processing portion of script
?>
<?
for ($j=0; $j<$number_of_uploads; $j++) {
?>
<input type=file name=img value=news.jpg size=30 id="img"><br>
<?
}
?>