chriscloyd Posted January 9, 2007 Share Posted January 9, 2007 heres my problem when i retrive the form with my php script its not showing multiple services from the services field so if i select more than one its not working it will only show the top onehow do i fix it ?heres my form[code]<form id="form1" name="form1" method="post" action="includes/send_quote.php"> <table width="253" border="0" cellspacing="5" cellpadding="0"> <tr> <td valign="middle"><div align="right" class="style17">First Name</div></td> <td><div align="center" class="style17">*</div></td> <td><input name="FirstName" type="text" class="input2" id="FirstName" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Last Name </div></td> <td><div align="center" class="style17">*</div></td> <td><input name="LastName" type="text" class="input2" id="LastName" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Phone # </div></td> <td><div align="center" class="style17">*</div></td> <td><input name="PhoneNumber" type="text" class="input2" id="PhoneNumber" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Email</div></td> <td><div align="center" class="style17">*</div></td> <td><input name="EmailAddress" type="text" class="input2" id="EmailAddress" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Budget </div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><span class="style17"> <label> <select name="budget" id="budget"> <option value="< $100">< $100</option> <option value="$100 - $200" selected>$100 - $200</option> <option value="$200 - $300">$200 - $300</option> <option value="$300 - $400">$300 - $400</option> <option value="$400 - $500">$400 - $500</option> <option value="$500 - $600">$500 - $600</option> <option value="$600 - $700">$600 - $700</option> <option value="$700 - $800">$700 - $800</option> <option value="$800 - $900">$800 - $900</option> <option value="$800 - $900">$800 - $900</option> <option value="$1000 - $2000">$1000 - $2000</option> <option value="$2000 - $3000">$2000 - $3000</option> <option value="$3000+">$3000+</option> </select> </label> </span></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">URL</div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><input name="url" type="text" class="input2" id="url" /></td> </tr> <tr> <td width="60" rowspan="2" valign="top"><div align="right" class="style17">Service</div> <span class="style17">Use Ctrlto select more than one</span></td> <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td width="164" rowspan="2" valign="top"><span class="style17"> <select name="services" size="4" multiple="multiple" id="services"> <option value="Web Desgin">Web Desgin</option> <option value="Logo/Branding Design">Logo/Branding Design</option> <option value="Web Development">Web Development</option> <option value="Other">Other</option> </select> </span></td> </tr> <tr> <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">If Other </div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><input name="other2" type="text" class="input2" id="other2" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Description</div></td> <td> </td> <td> </td> </tr> <tr> <td colspan="3"><div align="center" class="style17"> <textarea name="description" cols="25" rows="5" class="style21" id="description"></textarea> </div></td> </tr> <tr> <td><div align="right" class="style17">Refered By </div></td> <td> </td> <td><span class="style17"> <select name="refered"> <option value="">Select One</option> <?php $sales = mysql_query("select * from users where level in ('sales','admin') order by first, last asc"); while ($s = mysql_fetch_assoc($sales)) { echo '<option value="'.$s['id'].'">'.$s['first'].' '.$s['last'].'</option>'; } ?> </select> </span> </td> </tr> <tr> <td width="60"><input name="date" type="hidden" value="<?php echo date("n/j/Y g:i:s A"); ?>" /></td> <td width="9"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td width="164"><span class="style17"> <label> <input name="Submit" type="submit" class="input" onClick="MM_validateForm('FirstName','','R','LastName','','R','PhoneNumber','','RisNum','EmailAddress','','RisEmail');return document.MM_returnValue" value="Get Quote" /> </label> </span></td> </tr> </table></form>[/code] Quote Link to comment Share on other sites More sharing options...
curtis_b Posted January 9, 2007 Share Posted January 9, 2007 debug your query in phpmyadmin if you have it installed. 'where level in' is not valid Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 This is an HTML problem I think. Did you try printing the POST to see if they are set?Maybe you have to access it as an array, since you'll have several things with the same name.print_r($_POST); Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Curtis: Yes it is.http://www.tizag.com/sqlTutorial/sqlin.php Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 thats not the problem curtis its the services fieldhow would i access it like an array Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Did you do what I suggested and do print_r($_POST)? Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 try this instead for the service line:[code]<select name="services[]" size="4" multiple="multiple" id="services">[/code]what is happening is each one you select is over-writing the previous one, but if you make the name an array then when it is passed to php it becomes an array and you can retrive values much as jesirose said Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 i tried that and i got thisArray ( [test] => 6 [Submit] => Submit ) so how do i make it so it saves all of the things from the array in one var so i can save it into the database Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 You selected one from the services, and that is ALL you got from your post?Try the services[] name. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 how do i make it print so its not like this Array ( [test] => 6 [Submit] => Submit ) but like thisWeb DesignLogo Design Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 That's what print_r does. Is test the only input you are using when you fill out the form? It really should be printing out much more than that if you print_r($_POST); <-- exactly like that.You're seriously not getting other fields like your hidden ones? That seems...rather improbable. Quote Link to comment Share on other sites More sharing options...
curtis_b Posted January 9, 2007 Share Posted January 9, 2007 shoot sorry for the misinformation Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 You use a foreach loop instead. print_r is mostly for debugging. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 no its printitng out three i chooseits shoing the Array ( [test] => Array ( [0] => 1 [1] => 4 [2] => 5 ) [Submit] => Submit ) that on my tes form but i want it to show the info like this145 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Okay, you're missing the point.You said "when i retrive the form with my php script its not showing multiple services from the services field"Now, you have your multiple services. I guess you used test instead of services. When you process it, services is an array because there are multiple values.Now if you want to do something with that array, use foreach instead of print_r. Print_r was to make sure the values were being set.Your initial problem has been solved... Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 yes i know that im not missing the point i understand thatnow im trying to do the foreach loop[code]<?php if(isset($_POST['test'])){$a = $_POST['test[]'];foreach ($a) { $services .= $a.'<br />';}}?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Did you look up foreach?Turn error reporting on please, and look up functions if you have trouble using them. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 i just dont see how i can get each of the selctions into one variable Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 [code]foreach($array AS $value){ print $value.'<br />';}[/code] Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 yes but when i go to enter it into a database will it have them all under the variable value Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 9, 2007 Author Share Posted January 9, 2007 see i have that and it works fine but the problem im getting is saving all of them in one variable so i can add it to the database Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 the sugegstion i made, is not working for me when i try and call it on the second page..services[] does not seem to exist when i tried it, and services comes back as a single string stillhmmm Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Oh, try imploding it into a string.Look up implode() Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 Got it!Ignore the implode, i'll give ut he workign code, one moment.[code]<form id="form1" name="form1" method="post" action="myTest1.php"> <table width="253" border="0" cellspacing="5" cellpadding="0"> <tr> <td valign="middle"><div align="right" class="style17">First Name</div></td> <td><div align="center" class="style17">*</div></td> <td><input name="FirstName" type="text" class="input2" id="FirstName" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Last Name </div></td> <td><div align="center" class="style17">*</div></td> <td><input name="LastName" type="text" class="input2" id="LastName" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Phone # </div></td> <td><div align="center" class="style17">*</div></td> <td><input name="PhoneNumber" type="text" class="input2" id="PhoneNumber" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Email</div></td> <td><div align="center" class="style17">*</div></td> <td><input name="EmailAddress" type="text" class="input2" id="EmailAddress" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Budget </div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><span class="style17"> <label> <select name="budget" id="budget"> <option value="< $100">< $100</option> <option value="$100 - $200" selected>$100 - $200</option> <option value="$200 - $300">$200 - $300</option> <option value="$300 - $400">$300 - $400</option> <option value="$400 - $500">$400 - $500</option> <option value="$500 - $600">$500 - $600</option> <option value="$600 - $700">$600 - $700</option> <option value="$700 - $800">$700 - $800</option> <option value="$800 - $900">$800 - $900</option> <option value="$800 - $900">$800 - $900</option> <option value="$1000 - $2000">$1000 - $2000</option> <option value="$2000 - $3000">$2000 - $3000</option> <option value="$3000+">$3000+</option> </select> </label> </span></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">URL</div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><input name="url" type="text" class="input2" id="url" /></td> </tr> <tr> <td width="60" rowspan="2" valign="top"><div align="right" class="style17">Service</div> <span class="style17">Use Ctrlto select more than one</span></td> <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td width="164" rowspan="2" valign="top"><span class="style17"> <select name="services[]" size="4" id="services" multiple> <option value="Web Design">Web Design</option> <option value="Logo/Branding Design">Logo/Branding Design</option> <option value="Web Development">Web Development</option> <option value="Other">Other</option> </select> </span></td> </tr> <tr> <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">If Other </div></td> <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td><input name="other2" type="text" class="input2" id="other2" /></td> </tr> <tr> <td valign="middle"><div align="right" class="style17">Description</div></td> <td> </td> <td> </td> </tr> <tr> <td colspan="3"><div align="center" class="style17"> <textarea name="description" cols="25" rows="5" class="style21" id="description"></textarea> </div></td> </tr> <tr> <td><div align="right" class="style17">Refered By </div></td> <td> </td> <td><span class="style17"> <select name="refered"> <option value="">Select One</option> <?php $sales = mysql_query("select * from users where level in ('sales','admin') order by first, last asc"); while ($s = mysql_fetch_assoc($sales)) { echo '<option value="'.$s['id'].'">'.$s['first'].' '.$s['last'].'</option>'; } ?> </select> </span> </td> </tr> <tr> <td width="60"><input name="date" type="hidden" value="<?php echo date("n/j/Y g:i:s A"); ?>" /></td> <td width="9"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td> <td width="164"><span class="style17"> <label> <input name="Submit" type="submit" class="input" onClick="MM_validateForm('FirstName','','R','LastName','','R','PhoneNumber','','RisNum','EmailAddress','','RisEmail');return document.MM_returnValue" value="Get Quote" /> </label> </span></td> </tr> </table></form>[/code]Receiving page is this to print out just those values in the services array:[code]<?php if(isset($_POST['services'])){ $a = $_POST['services']; foreach($a as $b) { $c .= $b.'<br />'; }echo $c;}else {echo "not set";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 magic, implode does that "foreach" part for you. No need to reinvent the wheel... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.