Re: Help with writing multiple records to a table

From: Date: Tue, 03 Sep 2002 18:03:38 +0000
Subject: Re: Help with writing multiple records to a table
Groups: php.general 
Request: Send a blank email to php-general+get-115065@lists.php.net to get a copy of this message
>$_POST['category_id']; What do you think this does? Cuz it don't really "do" anything... > $numcat = count($category); > if ($numcat>1){ > $category_id=implode(",",$category); > } elseif ($numcat==1){ > $category_id=$category; > } You have an array of '$category' that you need to insert into cat_survey. Whether you have 1 or 40 or 0 items in it, it's an array. Actually, if they didn't pick anything, the variable won't even exist, so it won't be an array. And your count($category) will probably issue a Warning message... You need to do an INSERT for *every* category they chose: while (isset($category) && $category_id = each($category)){ > $cat=mysql_query("insert into cat_survey >(pfsurvey_id, > category_id) values >('$pfsurvey_id','$category_id')",$dbi); > if (!$cat) { > print "<p>Couldn't insert your record: >".mysql_error()."</p>\n"; > } } > print "<p>Loaded your data >correctly.</p>\n"; This is still going to prit out, even if something went wrong. Bad Human Interface. You'll be giving contradictory statements one after the other. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#115065) next »