/    Sign up×
Community /Pin to ProfileBookmark

php form handler

hey everyone i have a question about a form i have on my website.
its handled by a simple INSERT INTO php script. the problem i have is that there is a “category” field on the form that has 4 options.
the mysql database ive set up has 4 corresponding tables. can i use a set of conditionals to automatically send data to the correct table depending on what category they select?..or will i have to use a new form for each one?
any feed back would be great.
also, im new and id like to thank you guys in advance for any advice you have

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@blatant3authorOct 19.2004 — i think i might have it. will this work?



<form action="handle_form.php" method="post">

<select multiple name="catgory[ ]">

<option value=$_POST['"value"']>value</option>

<option value=$_
POST['"value"']>value</option>

<option value=$_POST['"value"']>value</option>

</select>

</form>

and then use:

INSERT INTO "database" WHERE category =

to determine what category is displayed?
Copy linkTweet thisAlerts:
@yunaOct 19.2004 — Just make the table definition in the SQL INSERT query a variable:

<i>
</i>$selected_category=$_POST["category"];
$query="insert into $selected_category (field, ..., field) values(value, ..., value);"


Then execute $query using the appropriate PHP command for your database.
Copy linkTweet thisAlerts:
@yunaOct 19.2004 — As an aside, in the long run you might find it easier to consolidate all the tables into one, making "category" a field in the consolidated table.
×

Success!

Help @blatant3 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.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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