parse multi-select input field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wescrock
Forum Commoner
Posts: 31
Joined: Wed Sep 10, 2008 10:31 am
Location: Fresno, CA

parse multi-select input field

Post by wescrock »

Hey all,

So, I have found how to echo the results of an input of a multi-select input field... but I cant seem to get it to go to the db...

here is all my code:
HTML Page (form)
<label>Subcategory:</label>
<?php
$result_category = @mysql_query("select id_lookup_category_, parent, category from wfbiblio.lookup_category where parent = 0");
print "<select multiple=\"true\" name=\"subcategory[]\" size=\"6\">\n";
while ($row = mysql_fetch_assoc($result_category)){
$id_lookup_category_ = $row['id_lookup_category_'];
$category = $row['category'];
print "<option value=$id_lookup_category_>$category\n";
}
print "</select>\n";
print "</p>\n";
?>
PHP page:
$id_lookup_subcategory=$_POST['subcategory'];
foreach ($id_lookup_subcategory_ as $subcategory){
$sql = "insert into wfbiblio.category_link (id_category_link_parent_, id_citation_, id_lookup_category_)
values ('$last_citation_id', '$last_id', '$subcategory')"; echo $sql;
$result = mysql_query($sql) or die (mysql_error()); }
can anyone see what is wrong with this code?

thanks all,
Wes
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: parse multi-select input field

Post by josh »

1) dont use error supression
2) output your query and compare the data in the query to what you would expect the data to be.
3) if you dont already see your mistake then post the query here so we can have atleast some idea of whats going on
Post Reply