php - how a website user interacts with a database? -
i'm new this, , can't seem find right search on google answer i'm looking for. have front end user use create new transaction. there drop down menu tied "categories" table has 1:m relationship "transaction" (see image). question is, if user submits form save new transaction, don't know id categories table, they'll doing selecting 1 drop down that's pulling categories table. know how @ point take input drop down , store field in transaction table. i'm trying understand how use relationships, in limited understanding of how keys work, seems unless knew id number was, relationship no good. if you're doing taking submission drop down , storing in transaction table, you've still got category name stored in 2 different tables, what's point? i'm missing step in here somewhere , i'm hoping can make sense out of this.
the user wouldn't know category id. (though if wanted to. it's in markup.) more importantly, code know category id. when creating drop down list (the select
element), code populating both id , name. id used value, name used display text.
the resulting markup might this:
<select name="category"> <option value="1">first category</option> <option value="2">second category</option> <option value="3">third category</option> </select>
and on.
when user selects one, they're choosing based on text. actual form post value of selected option server. if user selects second category
in server-side code $_post["category"]
contain value 2
, id need insert transaction record.
Comments
Post a Comment