Jump to content

please slove this country select array


blacktiger786

Recommended Posts

i have code which select country from html and its get multiply country in array i implement in php code to database save but not work please tell me what i do this is code

 

<span class="st-labeltext">Countries</span>    
                                        <label class="margin-right10"><input type="radio" id="r_all" name="countries" value="allc" class="uniform" /> All Countries</label>
                                        <label class="margin-right10"><input type="radio" id="r_selected" name="countries" value="selectedc" class="uniform"/> Selected Countries</label>
                                        <div id="clist_div" class="simplebox cgrid540-right" style="display:none;">
                                            <div style="padding:5px"></div>
                                            <div class="simplebox cgrid200-left">
                                                <p style="text-align:center;"><b>Excluded Countries</b></p>
                                                <select size="10" name="excludedcountries" style="width:200px; height:160px;" onDblClick="moveSelectedOptions(this.form['excludedcountries'],this.form['selectedcountries[]'])" multiple >
<option value='AF'>Afghanistan</option><option value='AX'>Aland Islands</option><option value='AL'>Albania</option><option value='DZ'>Algeria</option>

</div>
                                            <div class="simplebox cgrid40-left">
                                                <input class="button-blue" type="button" name="right" value=">>" onclick="moveSelectedOptions(this.form['excludedcountries'],this.form['selectedcountries[]'])"><br/><br/>
                                                <input class="button-blue" type="button" name="left" value="<<" onclick="moveSelectedOptions(this.form['selectedcountries[]'],this.form['excludedcountries'])">
                                            </div>
                                            <div class="simplebox cgrid200-left">
                                                <p style="text-align:center;"><b>Selected Countries</b></p>
                                                <select size="10" name="selectedcountries[]" style="width:200px; height:160px;" onDblClick="moveSelectedOptions(this.form['selectedcountries[]'],this.form['excludedcountries'])" multiple ></select>
                                            </div>
                                        </div>
                                          <div class="clear"></div>
                                    </div>

 

 

please tell me how to save selectedcountries[] array to php to mysql database save code

Link to comment
Share on other sites

if not under stand please tell me how to echo these select value from select[]

 <?php

if(isset($_POST['select[]']))
{

foreach ($_POST['select[]'] as $key => $value)
    {
       echo $value;
    }
}
?>
 <form action="arraycountry.php" method="POST">
 <select name="select[]" multiple="yes">
<option value="1">1 is selected</option> 
<option value="2">2 is selected</option> 
<option value="4">4 is selected</option> 
 <input type="submit" value="click">
 
 
 </select></form>
Link to comment
Share on other sites

this is my code its run file like i select to country from selected form its save it database but its save bot new row
like
1 usa
2 pk

i want its add both on single row like
1 usa,pk,uk

this is code..

 <?php
require 'databaseconnect.php';
if(isset($_POST['select']))
{
$movie = $_POST['select'];

foreach($movie AS $title) {


$run="INSERT INTO `test` VALUES ('','".$title."')";
$result=mysql_query($run); 
echo $title;
}

}
?>
 <form action="arraycountry.php" method="POST">
 <select name="select[]" multiple="yes">
<option value="usa">1 is selected</option> 
<option value="uk">2 is selected</option> 
<option value="pk">4 is selected</option> 
 <input type="submit" value="click">
 
 
 </select></form>
Link to comment
Share on other sites

That's probably a bad idea.  You might want to read up on database design and normalization so you don't run into problems down the road.  But the simple answer is this, with no foreach loop:

require 'databaseconnect.php';
if(isset($_POST['select']))
{
$movies = implode(',', array_map('mysql_real_escape_string', $_POST['select']));
$run    = "INSERT INTO `test` VALUES ('','$movies')";
$result = mysql_query($run);
}

Also, get off of the mysql_* functions and use mysqli_* or PDO.

Edited by AbraCadaver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.