0

i have this code here (simplified it a bit for this but you get the idea!) and i have assigned the name field of a select tag with a value of a variable so that when i click the Update button i can use _POST[name_var] to get the value of the select. however this returns the following error:

"Notice: Undefined index: 62"

if i manually put 62 in the name field and in the _POST[62] it does work so there is no problem with the rest of my code.

if anyone could tell me what i need to do to make this work i would be greatly appreciative!

Thanks in advance
Ollie

//role.php file
<?php
$name_var = 62;

echo '<form method="POST" action="update_role.php">';

echo '<select id="dropdown" name=$name_var>';
//option tags in here...
echo '</select>';

echo '<input type="submit" name="btn_update" id="button" value="Update" />';
echo '</form>';
?>

//update_role.php file
<?php
$name_var = 62;
$getVar = _POST[$name_var];
?>
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by geekman92
1

Some typos:

//role.php file
<?php
$name_var = 62;

echo '<form method="POST" action="update_role.php">';

echo "<select id=\"dropdown\" name=\"$name_var\">"; // WRONG QUOTING HERE
//option tags in here...
echo '</select>';

echo '<input type="submit" name="btn_update" id="button" value="Update" />';
echo '</form>';
?>

//update_role.php file
<?php
$name_var = 62;
$getVar = $_POST[$name_var]; // FORGOT THE DOLLAR SIGN
?>

Edited by pritaeas: n/a

Votes + Comments
Really good! Helpful and quick!! :D
0

Yessss that works! XD Thanks alot for your help and replying so quickly!! A+++

0

why are you putting everything under php codes,
my bro,..

<?php

$name_var = 62;
?>

<form action="update_role.php" method="post" >

<select id="dropdown" name="<?php echo $name_var ; ?> " >
</select>

<input type="submit" name="btn_update" id="button" value="Update" />
</form>


//update_role.php file
<?php
$name_var = 62;
$getVar = $_POST[$name_var];
?>

this will work too,..
remember, you can embed php code in html, so there is enough flexibility..!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.