getting the value from dropdown

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

getting the value from dropdown

Post 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. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What? The code snippet you've posted is only showing the select box. Where's the rest?
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thank you. im confused on how to implement that. sorry for my ignorance. :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Which?

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