PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: isset
isset - phponwebsites.com
Showing posts with label isset. Show all posts

13 Dec 2015

Get multiple selected values from drop down box using PHP

                           You can get value from selection box using $_POST['selection_box_name'] ( if form method is post) in PHP. Now the doubt is rise. How to select multiple values from drop down box and how to get multiple selected input data from drop down box in PHP. This post describes retrieve multiple selected values from drop down box using PHP.

How to select multiple values from drop down box in HTML


                           You know select single value in drop down box. Then how to select multiple values in drop down box. You have to add attribute "multiple" and set name as array in drop down box in order to select multiple values from drop down box. If you want to select more than one values in drop down box, then press "ctrl" while selecting values in drop down box. Let consider below example to make HTML formwith select multiple values in drop down box.

<!DOCTYPE html>
<html>
<body>
<form action="#" method="post">
<select name="country[]" multiple>
  <option value="USA">USA</option>
  <option value="United Kingdom">United Kingdom</option>
  <option value="Russia">Russia</option>
  <option value="Brazil">Brazil</option>
  <option value="India">India</option>
</select>
<input type="submit" name="submit">
</form>
</body>
</html>

Retrieve multiple selected values from drop down box using PHP


                                 You can get value from selection box using $_POST['selection_box_name'] ( if form method is post) in PHP. Then display each selected items through foreach loop in PHP. The PHP script describes how to select multiple selected values from drop down box.

<!DOCTYPE html>
<html>
<body>
<form action="#" method="post">
<select name="country[]" multiple>
  <option value="USA">USA</option>
  <option value="United Kingdom">United Kingdom</option>
  <option value="Russia">Russia</option>
  <option value="Brazil">Brazil</option>
  <option value="India">India</option>
</select>
<input type="submit" name="submit">
</form>
<?php
 if(isset($_POST['submit']))
 {
  $country=$_POST['country'];
  foreach($country as $val)
  {
    echo $val.'<br>';
  }
 }
?>
</body>
</html>

               
                                      While submitting form with selected multiple values from drop down box, you can get multiple selected values using PHP.

13 Aug 2015

Get value from drop down box using PHP

                        The drop down box allows you to select one or more values from it. The HTML tag "select" is also known as "drop down" or "pul down" box.You can get value from drop down box using PHP while form submitting.

HTML form with drop down box


                        The below example describes how to create HTML form with drop down box.

<html>
<body>
<form action="#" method="post">
  <select name="country">
     <option value="USA">USA</option>
     <option value="United Kingdom">United Kingdom</option>
     <option value="France">France</option>
     <option value="Russia">Russia</option>
     <option value="India">India</option>
  </select>
  <input type="submit" name="submit" value="Submit">
 </form>
 </body>
 </html>

Retrieve input data from drop down box using PHP


                       You can retrieve input data from drop down box using following types in PHP.
             $_POST['drop_down_name'] (if method is post)
             $_GET['drop_down_name'] (if method is gett)
             $_REQUEST['drop_down_name'] (if method is either post or get)
                         The following PHP script describes how to retrieve input data from drop down box while form submitting.

<html>
<body>
<form action="#" method="post">
   <select name="country">
      <option value="USA">USA</option>
      <option value="United Kingdom">United Kingdom</option>
      <option value="France">France</option>
      <option value="Russia">Russia</option>
      <option value="India">India</option>
   </select>
   <input type="submit" name="submit" value="Submit">
</form>
<?php
      if(isset($_POST['submit']))
      {
         $country=$_POST['country'];
         echo'You selected '.$country;
       }
?>
</body>
</html>

                             While submitting form with select country from drop down box, you can get selected country as output.

Related Post:

23 Jun 2014

How to store array values into session in php

                You can store single value to session in PHP easily. Visit store values to session in php.


Store array values to session in PHP:


                          You can also store multiple values into session using PHP. You can store one or more than one values in array that can be stored into session. Consider the following example. It describes the array values directly stored into session in PHP. The following PHP script is used to store values to session in PHP.

<?php
 session_start();
 $ar=array('php','mysql','jquery');
 $_SESSION['arr']=$ar;
 $session=$_SESSION['arr'];
 foreach($session as $val)
 {
   echo $val.'<br>';
 }
 ?>

 where,
            session_start() - start the session
            $ar=array() - array variable

                  Now you can get output like this:

                                    php
                                    mysql
                                    jquery

Store multiple (array) values into session in PHP on form submit:

                          Consider the following example:


 <html>
 <body>
 <?php
 session_start();
 error_reporting('E_ALL ^ E_NOTICE');
 if($_POST['submit'])
 {
  if(count($_SESSION['arr'])==0)
  {
   $ar=array();
   $val=$_POST['value'];
   array_push($ar,$val);
   $_SESSION['arr']=$ar;
   print_R($_SESSION['arr']);
  }
  else
  {
   $val=$_POST['value'];
   array_push($_SESSION['arr'],$val);
   print_R($_SESSION['arr']);
  }
 }
?>
 <form action="#" method="post">
  <input type="text" name="value">
  <input type="submit" name="submit" value="Submit">
 </form>
 </body>
 </html>


                    The above example describes array values are storing into session in PHP while form submitting.
            where,
                      if(count($_SESSION['arr'])==0) {} - check  whether the array contains values or not. Create array variable and store value into array, then value is stored into session if there is no values in session. Otherwise it directly add values into session.
                     array_push() - add values to array in PHP.

Related Post: