PHP Problem

Associate
Joined
29 May 2005
Posts
144
hello. I have a little problem adding to my database. i've cut my code short, but this is basically where im stuck. I'm currently populating a listbox with categorys from the `category` table. when i select the category i would like it to add to database with the value. I thought the following code would do the trick, but something has gone a bitty wrong somewhere.

the listbox contains the correct values, but when submit is pressed its not adding nothing to the database. where would i be going wrong?

should it be set as $_GET['category']; or $_POST['category'];?

thanks mofish ;)

Code:
<?
$selectedcategory = $_GET['category'];
$query = "insert into `gallery` (`image`, `author`, `category`) values ('$filename', '$member', '$selectedcategory')";
?>

<form action="index.php?page=upload" method="POST" enctype="multipart/form-data">

<?
$result = mysql_query("SELECT * FROM `category`");
$category = $myrow["category"];
			
	echo '<select name="selectedcategory">';
	while ($myrow = mysql_fetch_array($result)) {
	  $opt = $myrow['category'];
	  echo "<option>$opt</option> ";
	}
	echo '</select>';
?>

<input type="hidden" name="MAX_FILE_SIZE" value="10485760" class="loginbox">
<input type="file" name="imagefile" class="loginbox">
<input type="submit" name="upload" value="Upload Image" class="loginbox"></p>
</form>
<?
 
unknowndomain said:
It will depend on how the form is submiting it, now i presume you have some thing like this....

<form action="file.php" method="post">

if so then you need to put in

$_POST['category'];

otherwise

$_GET['category'];

Code:
<form action="index.php?page=upload" method="POST" enctype="multipart/form-data">

i have the following, its in my code above. so should i be using $_POST['category']; within the form, and $_GET['category'] outwith the form at the top of the page?
 
Oh right, I initially thought they were held in the same location. POST put the variable there, and GET took it back out. thats where I have been going wrong.

Thanks a lot Rob, that really cleared things up. working a perfect now. :p
 
Back
Top Bottom