/    Sign up×
Community /Pin to ProfileBookmark

POSTING extra data depending on HTML Select

I have a SQL query which returns the id (the primary key) and the name of a student.
Using a PHP loop I have auto-populated an HTML select drop down with the names and the user can select a student by name and then record a score for that student in a text input on the same form. That all works fine BUT …
The data is then POSTed to another php page to enter into the database. The results table needs the student’s id, not their name.
How can I get the id for the selected student and send as part of the POST?

Many thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 02.2015 — If it's a normal HTML select element, just set the value to the ID, e.g.:
[code=php]
echo "<option value='{$row['id']}'>{$row['name'}</option>";
[/code]
Copy linkTweet thisAlerts:
@abigbearauthorDec 02.2015 — Thanks heaps - I know it was so simple but I just couldn't see it. Works a treat now.
×

Success!

Help @abigbear spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...