Member Avatar

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];
?>

Recommended Answers

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 …
Jump to Post

All 4 Replies

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
?>
commented: Really good! Helpful and quick!! :D +1
Member Avatar

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

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..!!

Member Avatar

argh okay thats good to know too! thanks for the help!! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.