PHP Receive the ID of a value via select option

Asked

Viewed 27 times

2

Oops, guys, I’m developing a code and I’ve been at this part for days; I need to get a value to register it as a table ID.

This part of the code works perfectly. It demonstrates a dropdown of what I need. But I need to send the id linked to "time", unfortunately it is not sending. This is a dynamic select, all I need is to get the ID of one of the teams. Could someone help me? Thank you!!

1 answer

2


Your mistakes are just "in the part that’s working".

The first problem (it may just be failure to ask the question) is that the TAG is missing select with a name involving your option group. If this is missing from your code you cannot do this:

if (isset($_POST['time1'])) {
    $time1  = $_POST['time1'];
}
if (isset($_POST['time2'])) {
    $time2 = $_POST['time2'];
}

To solve this problem, add the selects with the name time1 and time2, as your need.

Ex:

<select  name=time2">
    <optgroup label="TIMES:">
    (...)
</select>

The 2nd problem is in the query made. It is only returned time_nome. Therefore, the value in selects are not filled.

To solve this problem you need to return the time id in select by changing the query and then using that id in the value select. The column name used as id was not indicated in the question, but supposing that it is id_time your code should be:

$result_time = "SELECT id_time, time_nome FROM time GROUP BY time_nome";

And then:

<option value="<?php echo $rows_time['id_time']; ?>"><?php echo $rows_time['time_nome']; ?></option>
  • Dias, had the name, was just an error after inserting the question here. I made the changes in select and option as you mentioned above, but unfortunately still no data go. ):

  • @matword then correct the question and check again that there is no other difference. There may be several mistakes, not sense the ones I pointed out to the ones.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.