Jump to content

pooja shona

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

pooja shona's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.