WS Subscription software
Premium Membership
graphics design php html youtube
Subscribe!
Not a premium user?
Subscriber and get access.
graphics design php html youtube
Live Support
Contact us by live help [photoshop, website design, tutorials]
Not available on weekends

Support our site with a small donation.
This Month: $
Total: $118.89
 
Login or Register to leave username.


ws©

Our Sponsors



Free e Cards of holidays, cute animals, nature and more
PHP Nuke themes, stock photos, icons, drupal themes and more.
Advertise with Western Studios.net
Custom jobs at low cost, free lancers and service buyers.



Latest Jobs





Western Studios :: View topic - PHP Multiple Dropdown Box Form Submit To MySQL (Part 2)
Need Jobs done? Use our brand new Jobs Board to get your projects done at affordable prices.
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups     ProfileProfile   Log inLog in 


PHP Multiple Dropdown Box Form Submit To MySQL (Part 2)



 
Post new topic   Reply to topicprinter friendly version    Western Studios Forum Index -> Web Design
Western Studios

Elite Member
Elite Member
~PHP Nuke User~


Posts: 1628
Next Group: 3372 posts
wsbot wrote:

This is a continuation of the discussion at



http://stackoverflow.com/questions/944158/php-multiple-dropdown-box-form-submit-to-mysql



which ended with the words: "Once you have the variables, it is trivial to create new rows." No doubt that's generally true, but apparently not for this learner... Very Happy



Given the following form:



    <form action="form.php" method="POST">

<select name="colors[]" multiple="yes" size="2">
<option>Red</option>
<option>Blue</option>
</select>
<input type="submit" value="Go!">
</form>


how do I create new rows? The following script



foreach($_POST['colors[]'] as $color) 

{
$id = mysqli_real_escape_string($link, $color);
$sql = "INSERT INTO colors SET id = '$id'";
}


raises the error



 Warning: Invalid argument supplied for foreach() in form.php on line ...



whereas the following



    $colors = $_POST['colors[]']; 

for ($i = 0; $i < count($colors); $i++)
{
$color = $colors[$i];
$sql = "INSERT INTO colors SET id = '$color'";
}


raises no errors but does no row creation.



What triviality am I missing here?



View Solution
PHP Multiple Dropdown Box Form Submit To MySQL (Part 2)

Posted: Mon Feb 08, 2010 1:01 pm

Post new topic   Reply to topic    Western Studios Forum Index -> Web Design All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Forums ©