Page 1 of 1

getting the value from dropdown

Posted: Mon Jun 04, 2007 8:56 pm
by pleigh
hi, i have this code

Code: Select all

$query =    "SELECT RKey, Description FROM hh_rights";
$result = mysql_query($query) ;
$num_total = @mysql_num_rows($result);
					
if ($num_total >= 0) {
						
     echo "<br><select name='rights' >\n";
     while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
     $rightsarr = $row[0];
     echo "<option value='" . $rightsarr . "' >" . $row[1] . "</option>";
}						
echo "</select>";
}
i can retrieve the values from the database, but the problem is that the $rightsarr, when writing its value in the database, i get the total number of rows instead of its value. how can i modify this?thanks a lot. :)

Posted: Mon Jun 04, 2007 9:24 pm
by feyd
What? The code snippet you've posted is only showing the select box. Where's the rest?

Posted: Mon Jun 04, 2007 9:30 pm
by pleigh
oh im sorry. i'll post it again

Code: Select all

$query =    "SELECT RKey, Description FROM hh_rights"; 
$result = mysql_query($query) ; 
$num_total = @mysql_num_rows($result); 
                                        
if ($num_total >= 0) { 
                                                
     echo "<br><select name='rights' >\n"; 
     while ($row = mysql_fetch_array($result, MYSQL_NUM)) { 
     $rightsarr = $row[0]; 
     echo "<option value='" . $rightsarr . "' >" . $row[1] . "</option>"; 
}                                           
echo "</select>"; 
}

if (isset($_POST['submit'])) {
     echo $rightsarr;
}

Code: Select all

<input type="submit" name="submit" value="save">
i just want to put the value of the option that i selected. if i have "anoption" in the <option> with the value = 1, i want to retrieve number 1 instead of the sum of all the values. because when i tried to do the above code, and i have 7 options, the value that i get is 7, and not the value of the selected option. hope this helps.

Posted: Mon Jun 04, 2007 9:34 pm
by feyd
$rightsarr is not in the submission data. It is created by you during the retrieval from the database.

The data will be in $_POST['right'] apparently.

Also, it's rarely a good idea to look for the submit button to tell if a submission has happened. No matter what, each submission value needs to be checked before use. $_SERVER['REQUEST_METHOD'] may be of interest too.

Posted: Mon Jun 04, 2007 9:43 pm
by pleigh
thank you. im confused on how to implement that. sorry for my ignorance. :oops:

Posted: Mon Jun 04, 2007 10:06 pm
by feyd
Which?

var_dump($_POST) to see what's in it.