0

I am new to PHP and I have a drop down list with multi values for addresses and I want to insert the selected values to the table persons, in my code I got only the first value : state but I couldn't get the rest values.what I should do to make it work? her is my file(test3.php):

<form action="test3.php" method="GET">
state :<select name="states">
<option value="state1">state1</option>
<option value="state2">state2</option>
<option value="state3">state3</option>
<option value="state4">state4</option>
</select><br>


   City :<select name="cities">
<option value="city1">city1</option>
<option value="city2">city2</option>
<option value="city3">city3</option>
<option value="city4">city4</option>
</select><br>


   zipcode :<select name="zipcodes">
<option value="zipcode1">zipcode1</option>
<option value="zipcode2">zipcode2</option>
<option value="zipcode3">zipcode3</option>
<option value="zipcode4">zipcode4</option>
</select><br>



   Name :<select name="names">
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
<option value="name4">name4</option>
</select><br>


<input type="submit" name="submit" value="Insert">
</form>
<?php
if(isset($_GET['states']))
{
    $name=$_GET['states'];
    $c=mysql_connect("localhost","user","");
    mysql_select_db("db");
    $ins=mysql_query("INSERT INTO `persons` 
                      (state)
                      VALUES ('$name')",$c);


}


?>
Phil
  • 157,677
  • 23
  • 242
  • 245
hussam
  • 41
  • 2
  • Can you add the structure of the table "persons"? – Mohamed Chaawa Feb 11 '18 at 23:27
  • 3
    Please note the `mysql_` constructor is [**deprecated as of PHP 5.5**](https://wiki.php.net/rfc/mysql_deprecation), and is [**removed in PHP 7**](https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7#extmysql). Please consider switching to either [**MySQLi**](http://php.net/manual/en/book.mysqli.php) or [**PDO**](http://php.net/manual/en/book.pdo.php), ensuring that you also use [**prepared statements**](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) to prevent [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) :) – Obsidian Age Feb 11 '18 at 23:30
  • 2
    What do you mean by _"couldn't get the rest values"_? They should be in `$_GET['states']`, `$_GET['cities']`, `$_GET['zipcodes']` and `$_GET['names']`. If you're wondering how to insert them all into the same row, I suggest you read the fine manual ~ https://dev.mysql.com/doc/refman/5.7/en/insert.html – Phil Feb 11 '18 at 23:32
  • What I *think* you're looking for is to have your ``, in addition to the `multiple` attribute. However, this question has been asked **numerous** times before (with [**this question**](https://stackoverflow.com/questions/32306345/how-to-insert-values-of-multiple-select) seeming to be the most similar). – Obsidian Age Feb 11 '18 at 23:34
  • my table has 5 col: Id , State , City, Zipcode & name – hussam Feb 12 '18 at 03:16
  • this code is working – hussam Feb 15 '18 at 23:48

0 Answers0