MGLP Posted March 26, 2018 Share Posted March 26, 2018 I display a variable number of records and each one has a Radio button for the user to select. Each record has a unique serial number. How can I determine which record was selected and pass this on to my next php file. e.g. of my code: While($cntr < $NumRcds) { $cntr=$cntr+1; if ($AffectedRows > 0) { ($Row = mysql_fetch_row($Results)); print("<input type=\"radio\" name=\"rcd\" id=\"rcd\" value=\"$Row[6]\">); $AffectedRows=$AffectedRows-1; } } Thank you Link to comment Share on other sites More sharing options...
dsonesuk Posted March 26, 2018 Share Posted March 26, 2018 IF it is part of form it will be set using method 'get' or 'post' to the set file url in 'action' attribute. The page it is sent to then reads the value from $_POST['rcd'] or $_GET['rcd'], whichever 'method' was set in the form. Link to comment Share on other sites More sharing options...
MGLP Posted March 26, 2018 Author Share Posted March 26, 2018 I am using the POST method and it doesn't work. The $_POST['rcd'] does not contain anything. It only works if I do a separate print for each record (instead of a loop routine as in my above code) and if I give each <input> tag a separate name/id, e.g., rcdA, rcdB, rcdC, etc. But I dont't want to do this - that's not the way to programme and I also don't know how many records - it's avariable number everytime. So the question is how do I get to pass the "rcd" when using the loop method. Link to comment Share on other sites More sharing options...
MGLP Posted March 26, 2018 Author Share Posted March 26, 2018 OK. I had to make the "name" different from the "id" in the <input> tag. <input type=\"radio\" name=\"rcd\" id=\"rcd\" value=\"$Row[6]\"> DOES NOT WORK <input type=\"radio\" name=\"choice\" id=\"rcd\" value=\"$Row[6]\"> WORKS Thanks for your help! Link to comment Share on other sites More sharing options...
dsonesuk Posted March 26, 2018 Share Posted March 26, 2018 (edited) It should work, just because it is not working at this moment doesn't mean this method is wrong! It just means that there is some mistake that is preventing it from working. You can only select 1 single radio button at a time, so we know 'rcd' is not the problem, (Note the id ref will be wrong! As it will produce multiple duplicate id references, when they can only be unique within a page). You can do a simple test to produce 3 radio non dynamically with plain html and see if the php page will pick up the selected value. If it work you have to produce the same result as the manual entered html. <form method="post" action="somephppage.php"> <input type="radio" name="rcd" id="rcd0" value="111111"> <input type="radio" name="rcd" id="rcd1" value="222222"> <input type="radio" name="rcd" id="rcd2" value="333333"> <input type="submit" name="rcdsubmit" value="Submit to PHP page In action"> </form> somephppage.php echo $_POST['rcd']; Edited March 26, 2018 by dsonesuk Link to comment Share on other sites More sharing options...
MGLP Posted March 26, 2018 Author Share Posted March 26, 2018 Thank you dsonesuk. From what I can see it was because the "name" and "id" were both "rcd". As soon as I mad the "name" different, it worked beautifully. Many thanks. Link to comment Share on other sites More sharing options...
dsonesuk Posted March 26, 2018 Share Posted March 26, 2018 Unless you using JavaScript dot notation in some way to submit the form, it should make no difference <input type="radio" name="rcd" id="rcd" value="111111"> <input type="radio" name="rcd" id="rcd1" value="222222"> <input type="radio" name="rcd" id="rcd2" value="333333"> Will work just as well 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