yangkai9999 Posted November 5, 2009 Report Share Posted November 5, 2009 Hello,I can use the following PHP code to retrive values as a pull donw list.I tried to pass the selected value to a post variable, like $p_id. But it doesn't work.How to do that?Thank you, echo "Please choose a patient for update: ";echo "<select id='num' Onchange='changeLocation(this)' >";echo "<option selected>";$i=0;$query="SELECT p_id from mytest.p2 order by P_ID;";$results = mysql_query($query) or die('no such table exist ' . mysql_error());;while ($row=mysql_fetch_row($results)){ if ($i == 0) { $i++; echo "<option value='./mytest2/update2.php?p_id=$row[0]'>$row[0] </option>"; }else { echo "<option value='./mytest2/update2.php?p_id=$row[0]'>$row[0]</option>"; echo "$row[0]"; }}echo "</select>";$row=$p_id;echo $p_id;++$i; Link to comment Share on other sites More sharing options...
justsomeguy Posted November 5, 2009 Report Share Posted November 5, 2009 Give the select box a name, that name will be used for the key in the $_POST array. Link to comment Share on other sites More sharing options...
yangkai9999 Posted November 5, 2009 Author Report Share Posted November 5, 2009 Give the select box a name, that name will be used for the key in the $_POST array.Just like this?echo "Please choose a patient for update: ";echo "$p_id=$_post('selection')";echo "<select id='num' Onchange='changeLocation(this)' >";echo "<option selected>"; Link to comment Share on other sites More sharing options...
yangkai9999 Posted November 5, 2009 Author Report Share Posted November 5, 2009 Give the select box a name, that name will be used for the key in the $_POST array.or this one:echo "<select id='num' Onchange='changeLocation(this)' name=getid>";echo "<option selected >";$i=0;$query="SELECT p_id from mytest.p2 order by P_ID;";$results = mysql_query($query) or die('no such table exist ' . mysql_error());;while ($row=mysql_fetch_row($results)){ if ($i == 0) { $i++; echo "<option value='./mytest2/update2.php?p_id=$row[0]'>$row[0] </option>"; }else { echo "<option value='./mytest2/update2.php?p_id=$row[0]'>$row[0]</option>"; echo "$row[0]"; }}echo "</select>";++$i;$p_id=$_post[getid];echo $p_id; Link to comment Share on other sites More sharing options...
justsomeguy Posted November 5, 2009 Report Share Posted November 5, 2009 I'm talking about subitting a form normally. If you have a select box like this:<form method="post"><select name="var"><option value="1">one</option></select><input type="submit"></form>If you select that option and submit the form, $_POST['var'] will contain "1".If you're trying to redirect to the URL in the option value, then the code you have should work, but the value is not going to be in $_POST, it's going to be in $_GET. $_GET['p_id'] should contain the value of a querystring variable called p_id. Link to comment Share on other sites More sharing options...
yangkai9999 Posted November 5, 2009 Author Report Share Posted November 5, 2009 I'm talking about subitting a form normally. If you have a select box like this:<form method="post"><select name="var"><option value="1">one</option></select><input type="submit"></form>If you select that option and submit the form, $_POST['var'] will contain "1".If you're trying to redirect to the URL in the option value, then the code you have should work, but the value is not going to be in $_POST, it's going to be in $_GET. $_GET['p_id'] should contain the value of a querystring variable called p_id.Thanks a lot. This is very detail instruction and very useful.Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now