Jesus Rodriguez
Jesus Rodriguez

Reputation: 2611

getting value of <option> with $_POST gives text

So, I'm retrieving these options from a database

select and options

and I need to retrieve the value but I'm getting the text in between the tags

<option></option>

by doing this

$inst = $_POST['inst'];

therefore if I print $inst I get the "IUTIRLA" for the first option but I need the 41

I don't know what I'm doing wrong... this is how I'm printing the html through php

echo "<option value=".$cod_institucion.">".$nombre_institucion."</option>";

Upvotes: 0

Views: 180

Answers (4)

Nishu Tayal
Nishu Tayal

Reputation: 20820

here you need to correct php code, as it is not parsing the values properly. Put values under quotes.

echo "<option value='".$cod_institucion."'>".$nombre_institucion."</option>";

Upvotes: 1

TravisO
TravisO

Reputation: 9540

Change your code like this

echo '<option value="'. $cod_institucion .'">'. $nombre_institucion .'</option>';

When outputting HTML, it's going to be easier to use single quotes, that way the double quotes inside your HTML don't have to be escaped.

Upvotes: 1

Kylie
Kylie

Reputation: 11749

You need to do this...

echo "<option value='".$cod_institucion."'>".$nombre_institucion."</option>";

Upvotes: 0

Rob W
Rob W

Reputation: 9142

Maybe you have $cod_institucion and $nombre_institucion backwards.

Upvotes: 0

Related Questions