title: How to retrieve value from a select box?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: “Notice: Undefined variable”  and “Notice: Undefined index”</a>  </p>
  </blockquote>
  
  
  
  <p>In html code:</p>
  
  <pre><code>&lt;select name="123023d"&gt;
   &lt;option value="default"&gt;Not Share&lt;/option&gt;
   &lt;option value="read"&gt;Read Only&lt;/option&gt;
   &lt;option value="edit"&gt;Editable&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>In php code:</p>
  
  <pre><code>$rights=$_POST['123023d'];
  </code></pre>
  
  <p>Why i can not retrieve the value of this select box?</p>
  
  <pre><code>Notice: Undefined index: 123023d in C:\xampp\htdocs\fyp\list\add.php on line 87
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>I am sure it is in the form and it is a post method. It is located after     <code>foreach ($result as $set)</code>  as you can see i draw some sql value to generate that select box and the name of the select box is userID</p>
  
  <p>Whole part:</p>
  
  <pre><code>&lt;form id="addlist" method="post" action="add.php" &gt;
  &lt;h1&gt;Create your new subscriber list&lt;/h1&gt; 
  &lt;p&gt;Create a new list before adding subscriber &lt;label class="right"&gt;&lt;em class="dot"&gt;*&lt;/em&gt; indicates required&lt;/label&gt;&lt;/p&gt;
  
  &lt;label&gt;&lt;em class="dot"&gt;*&lt;/em&gt; List name:
  &lt;span class="small"&gt;Add your list name&lt;/span&gt;
  &lt;/label&gt;
  &lt;input id="lname" name="lname" class="required" /&gt;
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;label&gt;Reminder:
  &lt;span class="small"&gt;Remind the details of your list&lt;/span&gt;
  &lt;/label&gt;
  &lt;textarea id="creminder" name="creminder" cols="52" &gt;&lt;/textarea&gt;
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;p&gt;Email me when ...&lt;/p&gt; 
  &lt;label&gt;People subscribe:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="subscribe" value="1"&gt;
  &lt;label&gt;People unsubscribe:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="unsubscribe" value="1"&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/br&gt;
  
  &lt;div id="stylized" class="myform"&gt;
  
  &lt;p&gt;Permission Setting ...&lt;/p&gt;
  
  &lt;label&gt;Open to other users:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="public" value="1"&gt;
  Or
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  Select the permission for individual user:
  
  &lt;?
  $sql =
      "SELECT  UserID,Name,Rights,Position
      FROM     user
      WHERE UserID != ?
      AND Rights != 'Admin'
      ";
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute(array($_SESSION['username']));
  
  $num_rows= $stmt-&gt;rowCount();
  
  if ($num_rows != 0){
  $result = $stmt-&gt;fetchAll();
  ?&gt;
  
  &lt;table width="100%" class="display" id="viewSub"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th field="col1" width="40%"&gt;Name:&lt;/th&gt;
  &lt;th field="col2" width="40%"&gt;Position:&lt;/th&gt;
  &lt;th field="col2" width="20%"&gt;Permission:&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;?
  foreach ($result as $set) 
  {
      echo "&lt;tr&gt;&lt;td&gt;".$set['Name']."&lt;/td&gt;&lt;td&gt;".$set['Position']."&lt;/td&gt;&lt;td&gt;&lt;select name=".$set['UserID']."&gt;&lt;option value='default'&gt;Not Share&lt;/option&gt;&lt;option value='read'&gt;Read Only&lt;/option&gt;&lt;option value='edit'&gt;Editable&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;";
  }
  ?&gt;
  &lt;/tbody&gt; 
  &lt;/table&gt;
  
  &lt;?
  }
  else
  echo "There is no another user in this system";
  ?&gt;
  
  
  &lt;input class="submit" type="submit" name="submit" value="Submit"/&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>add.php  which is the form and the result process</p>
  
  <pre><code>&lt;?
  include("../connection/conn.php");
  session_start();
  
  if($_SERVER['REQUEST_METHOD'] == "POST"){
  print_r($_POST);
  exit();
  if (!isset($_POST['subscribe']))
  $_POST['subscribe']=0;
  if (!isset($_POST['unsubscribe']))
  $_POST['unsubscribe']=0;
  if (!isset($_POST['public']))
  $_POST['public']=0;
  
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  
  
  try {
  
      $listName = $_POST['lname'];
      $listRemindSub = $_POST['subscribe'];
      $creator = $_SESSION['username'];
      $listRemindUnSub = $_POST['unsubscribe'];
      $isPublic = $_POST['public'];
      $listReminder = $_POST['creminder'];
  
  
      $query="INSERT INTO list (ListID,ListName,Creator,IsRemindSub,IsRemindUnSub,IsPublic,CreateDate,Reminder) VALUES ('',?,?,?,?,?,CURDATE(),?)";
      $stmt = $conn-&gt;prepare($query);
  
  
      $stmt-&gt;bindParam(1, $listName , PDO::PARAM_STR);
      $stmt-&gt;bindParam(2, $creator, PDO::PARAM_STR);
      $stmt-&gt;bindParam(3, $listRemindSub, PDO::PARAM_INT);
      $stmt-&gt;bindParam(4, $listRemindUnSub, PDO::PARAM_INT);
      $stmt-&gt;bindParam(5, $isPublic, PDO::PARAM_INT);
      $stmt-&gt;bindParam(6, $listReminder, PDO::PARAM_STR);
  
      $stmt-&gt;execute();
  
  
  }
  catch(PDOException $e)
      {
      die ($e-&gt;getMessage().'&lt;a href="add.php"&gt; Back&lt;/a&gt;'); 
      $conn-&gt;rollBack();
      }
  
  
  try {
      $lastID=$conn-&gt;lastInsertId();
      $query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'Email','{email}')";
      $stmt = $conn-&gt;prepare($query);
      $stmt-&gt;execute();
      $query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'FirstName','{fname}')";
      $stmt = $conn-&gt;prepare($query);
      $stmt-&gt;execute();
      $query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'LastName','{lname}')";
      $stmt = $conn-&gt;prepare($query);
      $stmt-&gt;execute();
  }
  catch(PDOException $e)
      {
      die ($e-&gt;getMessage().'&lt;a href="add.php"&gt; Back&lt;/a&gt;'); 
      $conn-&gt;rollBack();
      } 
  
  try{
  $sql = '
  SELECT UserID
  FROM user
  WHERE Rights != ?';
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute(array('admin'));
  $result= $stmt-&gt;fetchAll();
  }
  catch(PDOException $e)
      {
      die ($e-&gt;getMessage().'&lt;a href="add.php"&gt; Back&lt;/a&gt;'); 
      }
  
  foreach ($result as $set)
  {   
  if ($set['UserID']==$_SESSION['username'])
  $rights='edit';
  else
  {$rights=$_POST[$set["UserID"]];
  $rights=$_POST['123023d'];}
  
  
  
  if ($rights != 'default' || $set['UserID']==$_SESSION['username'] || $_POST['public']==0)
  { 
  $user=$set['UserID'];
  try {
      $query="INSERT INTO user_list(UserID,ListID,UserRights) VALUES ('$user',$lastID,'$rights')";
      $stmt = $conn-&gt;prepare($query);
      $stmt-&gt;execute();
  
  }
  catch(PDOException $e)
      {
      die ($e-&gt;getMessage().'&lt;a href="add.php"&gt; Back&lt;/a&gt;'); 
      $conn-&gt;rollBack();
      }  
  }
  }
  
  $conn = null;
  
  ?&gt;
  &lt;div id="stylized" class="myform"&gt;
  &lt;div style="text-align:center;font-weight:bold;"&gt;You have created a list. By default Mail Address, First Name , Last Name is in your list. Add more field if you want. &lt;a href='add.php'&gt;Back&lt;/a&gt;&lt;/div&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;?
  }else{?&gt;
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  
  &lt;style type="text/css"&gt;
        @import "../plugin/easyui/themes/default/easyui.css";
        @import "../plugin/easyui/themes/icon.css";
        @import "../style/form.css";
        @import "../plugin/datatable/media/css/demo_page.css";
        @import "../plugin/datatable/media/css/demo_table.css";
  &lt;/style&gt;
  &lt;script src="../plugin/jquery-1.6.1.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="../plugin/easyui/jquery.easyui.min.js"&gt;&lt;/script&gt;
  &lt;script src="../plugin/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="../plugin/datatable/media/js/jquery.dataTables.js"&gt;&lt;/script&gt;
  &lt;script src="../plugin/jquery.form.js"&gt;&lt;/script&gt;
  
  
  &lt;script&gt;
  $(document).ready(function(){
  $("#addlist").validate();
  });
  
  
  $(document).ready(function() {
      $('#viewSub').dataTable();
      } );
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="stylized" class="myform"&gt;
  &lt;form id="addlist" method="post" action="add.php" &gt;
  &lt;h1&gt;Create your new subscriber list&lt;/h1&gt; 
  &lt;p&gt;Create a new list before adding subscriber &lt;label class="right"&gt;&lt;em class="dot"&gt;*&lt;/em&gt; indicates required&lt;/label&gt;&lt;/p&gt;
  
  &lt;label&gt;&lt;em class="dot"&gt;*&lt;/em&gt; List name:
  &lt;span class="small"&gt;Add your list name&lt;/span&gt;
  &lt;/label&gt;
  &lt;input id="lname" name="lname" class="required" /&gt;
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;label&gt;Reminder:
  &lt;span class="small"&gt;Remind the details of your list&lt;/span&gt;
  &lt;/label&gt;
  &lt;textarea id="creminder" name="creminder" cols="52" &gt;&lt;/textarea&gt;
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;p&gt;Email me when ...&lt;/p&gt; 
  &lt;label&gt;People subscribe:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="subscribe" value="1"&gt;
  &lt;label&gt;People unsubscribe:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="unsubscribe" value="1"&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/br&gt;
  
  &lt;div id="stylized" class="myform"&gt;
  
  &lt;p&gt;Permission Setting ...&lt;/p&gt;
  
  &lt;label&gt;Open to other users:&lt;/label&gt; &lt;input type="checkbox" class="checkbox" name="public" value="1"&gt;
  Or
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  Select the permission for individual user:
  
  &lt;?
  $sql =
      "SELECT  UserID,Name,Rights,Position
      FROM     user
      WHERE UserID != ?
      AND Rights != 'Admin'
      ";
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute(array($_SESSION['username']));
  
  $num_rows= $stmt-&gt;rowCount();
  
  if ($num_rows != 0){
  $result = $stmt-&gt;fetchAll();
  ?&gt;
  
  &lt;table width="100%" class="display" id="viewSub"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th field="col1" width="40%"&gt;Name:&lt;/th&gt;
  &lt;th field="col2" width="40%"&gt;Position:&lt;/th&gt;
  &lt;th field="col2" width="20%"&gt;Permission:&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;?
  foreach ($result as $set) 
  {
      echo "&lt;tr&gt;&lt;td&gt;".$set['Name']."&lt;/td&gt;&lt;td&gt;".$set['Position']."&lt;/td&gt;&lt;td&gt;&lt;select name=".$set['UserID']."&gt;&lt;option value='default'&gt;Not Share&lt;/option&gt;&lt;option value='read'&gt;Read Only&lt;/option&gt;&lt;option value='edit'&gt;Editable&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;";
  }
  ?&gt;
  &lt;/tbody&gt; 
  &lt;/table&gt;
  
  &lt;?
  }
  else
  echo "There is no another user in this system";
  ?&gt;
  
  
  &lt;input class="submit" type="submit" name="submit" value="Submit"/&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;/form&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;div id="stylized" class="myform"&gt;
  &lt;?
  try{
  $sql = '
      SELECT   *
      FROM     list,user_list
      WHERE    user_list.UserID=?
      AND list.ListID=user_list.ListID
  ';
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute(array($_SESSION['username']));
  $result= $stmt-&gt;fetchAll();
  $num_rows= $stmt-&gt;rowCount();
  }
  catch(PDOException $e)
      {
      die ($e-&gt;getMessage().'&lt;a href="add.php"&gt; Back&lt;/a&gt;'); 
      }
  $conn = null;
  if ($num_rows == 0) {
      echo '&lt;div style="text-align:center;font-weight:bold;"&gt;You have not created any list yet.&lt;/div&gt;';}
  else {
      echo '&lt;h1&gt;Your Subscriber List&lt;/h1&gt; &lt;p&gt;You have created '.$num_rows.' list(s).&lt;/p&gt;';
  foreach ($result as $set) 
  {
  echo '&lt;div style="font-weight:bold;"&gt;List Name : '.$set['FromName'].'&lt;/div&gt;&lt;br&gt;';
  echo '&lt;div style="font-weight:bold;"&gt;Subscriber : &lt;/div&gt;&lt;br&gt;';
  echo '&lt;div style="font-weight:bold;"&gt;Create Date : '.$set['CreateDate'].'&lt;/div&gt;&lt;br&gt;';
  echo '&lt;hr&gt;';
  }}
      ?&gt;
  &lt;div class="spacer"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  
  &lt;?
  }
  ?&gt;
  </code></pre>