pooja shona Posted March 3, 2010 Share Posted March 3, 2010 Hi,I am trying to solve following php prob. from three days, but it fails.Please help me. I have one php form with Name(textbox) and multivalue listbox with values mumbai, pune, nasik, surat, dhule. It work when user submits name and multiple cities as follows, //insert.php <?php $con=mysql_connect("localhost","root",""); $db=mysql_select_db('state'); $name=$_POST['name']; //$city=$_POST['city']; $abc=$_POST['city']; for ($i=0; $i<count($abc); $i++) { $city = $city." ".$abc[$i]; } $submit=$_POST['submit']; if(!empty($submit)) { $query=mysql_query("insert into city(name,city) values('$name','$city')"); } ?> Above code is working. But the problem is that, I want listbox on another page, this listbox should display the name of all cities, but should show all that cities which the selected while submitting the form with selected. //show.php <?php $con=mysql_connect("localhost","root",""); $db=mysql_select_db('state'); $query=mysql_query("select city from city where id=7"); $row=mysql_fetch_array($query); $one=$row["city"]; $pieces = explode(" ", $one); //echo $pieces[0]; // piece1 ?> <body> <select name="city[]" size=5 multiple="multiple"> <option value="pune"<?php if ($pieces[1] == 'pune') { echo 'selected="selected"'; } ?>>pune</option> <option value="mumbai"<?php if ($pieces[2] == 'mumbai') { echo 'selected="selected"'; } ?>>mumbai</option> <option value="nasik"<?php if ($pieces[3] == 'nasik') { echo 'selected="selected"' ;} ?>>nasik</option> <option value="surat"<?php if ($pieces[4] == 'surat') { echo 'selected="selected"'; } ?>>surat</option> <option value="dhule"<?php if ($pieces[5] == 'dhule') { echo 'selected="selected"'; } ?>>dhule</option> </select> </body> It doen't work.Could anyone tell me that what should I do? :'( [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/193980-listbox/ Share on other sites More sharing options...
ferdi Posted March 3, 2010 Share Posted March 3, 2010 For the insert.php script, how does your form look like? On the show.php script, there are a few things I don't get; Why are to splitting the $row["city"] variable? What does it hold in the database? Your making something simple to complex here, my best advice is for you to try and do it in a more simpler way. Link to comment https://forums.phpfreaks.com/topic/193980-listbox/#findComment-1020824 Share on other sites More sharing options...
inversesoft123 Posted March 3, 2010 Share Posted March 3, 2010 Run a while loop to select cities from database. why to explode ? <select name="city[]" is useless Link to comment https://forums.phpfreaks.com/topic/193980-listbox/#findComment-1020828 Share on other sites More sharing options...
man12_patil3 Posted March 3, 2010 Share Posted March 3, 2010 Pooja u need to submit array for selected cities which user select and store it in Db after that in next page fetch it and explode the array u will get the value of selected city.. Link to comment https://forums.phpfreaks.com/topic/193980-listbox/#findComment-1020843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.