1

I'm trying to fetch several data from a select list. I have the value as $_POST['valt_skift']. But I also like to send name. How can I do this?

This is what I got:

<select id="valt_skift" name="valt_skift">
  <option></option>
  <?php
    //Loop put result
    while($row = $stmt->fetch()){
      echo '<option name="skift_name['.$row['skift_name'].']" value="'.$row["skift_type"].'">'.$row["skift_namn"].'</option>';
    }
  ?>
</select>

The fetch:

$query_params = array( 
    ':usr_skift' => $_POST['skift_name'][0], //Here is my question?!
    ':usr_skift_type' => $_POST['valt_skift']); //this will be the value

1 Answer 1

1

You have typo within your code, you can't have name attribute within option value.If you want to get two values from the selected option then you can send it as

echo "<option value='{$row['skift_type']}@@@{$row['skift_name']}'>{$row['skift_name']}</option>";

This way you'll get the values along with the name within your $_POST['valt_skift'] as

echo $_POST['valt_skift']; // your_value@@@your_name

now you can get two values within one select option using explode you can fetch them both as

$get_skift = explode('@@@',$_POST['valt_skift']);
$usr_skift_type = $get_skift[0];//your_value
$usr_skift = $get_skift[1];//your_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.