I have a very basic form consisting of only two dropdown boxes (though the contents of the second dropdown vary depending on the selection made in the first). I then have a bit of text that displays under the second dropdown box once a selection has been made, and what the text says is unique to whatever selection is made.
What I want to be able to do is have this information directly publish into a table that will be included at the bottom of the same page the form is located on, once a user hits the submit button. In other words, when a user submits the form, I don't want it to simply spit the user's info back to them; I want the info to actually publish to the page in a table, so that anyone who logs in can see it, and can add their own published info to the table as well.
You could think of it sort of like a blog commenting system that automatically publishes new content to the page every time a visitor submits the form, except, instead of text areas that allow users to insert whatever they want, I have dropdown boxes that only allow them to select a certain option, and then have that selected info publish to a table.
How would I go about doing this? I have a beginner's knowledge of PHP, and almost no knowledge of javascript. But depending on how detailed and helpful of an answer that may be provided, I could work with either.
This form is only accessible to members who are logged in, and I have 6 bits of info that I want to have published into a row of 6 columns in the table every time a user hits Submit. Those 6 things are: (1) Username, (2) Time Stamp (Date & Time at which the form was submitted), (3) Selection result of 1st Dropdown, (4) Selection result of 2nd Dropdown, (5) The unique text that is displayed according to whichever selection is made in the 2nd dropdown, and (6) a second time stamp which is calculated as 30 days beyond the time generated in the 2nd column.
Any help would be appreciated. I'm experimenting with PHP a bit but my knowledge is really not advanced enough yet to really allow me to progress much of anywhere on my own.
EDIT:
I did some playing around earlier and have made a few changes. First, I'm now wanting 1 dropdown box, not 2. Second, there are 9 columns in the table, not 6. Third, I have a database with the following 4 tables:
table: members
member_id
firstname
lastname
login
passwd
rank_id
table: ranks
id
name
table: jobs
id
name
requirement_1
requirement_2
requirement_3
salary
rank_id
table: workorders
date
username
rank
job
requirement_1
requirement_2
requirement_3
salary
due_date
Here is the current site I am working on: http://www.kiithsoban.com/membership
You may use a guest login to gain access:
Username: username
Password: password
This is a personal project made for an online gaming clan (in EVE Online), with all of maybe 20 unique visitors a month, so quality and proper coding technique is not much of an issue (not at this point anyway). The primary concern is simply that it will work.
The reason I suggested posting a PHP table rather than taking the javascript route is because I already have a table created in a database (and I'm also more familiar with PHP and just want to get the first version of this online ASAP), and I already have it posting to the website as well, as you'll see on the above page. This is the "workorders" table.
You'll notice upon logging in that there are instructions on the index page referring to a dropdown box, which does not yet exist. The dropdown box will consist of 49 "jobs" to select from. When a user selects an option and submits the form, I want their selection to insert into the "job" field of the workorders table on my database; and, I also want the site to detect the additional information in the other 8 fields in order to automatically insert them as well.
I've been experimenting with one idea, but I'm not sure if it would work, or how to do it exactly. In my members and jobs tables, I've included a "rank_id" field, in which each entry will have a matching value to the "id" field in the ranks table. Now, there are 49 "jobs" to choose from, however, depending on what rank a user is, their job salary will vary (given that there are 7 ranks, 49 * 7 = 343 total possible job/salary combinations that can result from the form submission). What I want the site to do is detect the logged in user's "rank_id" (in the members table), and after the user selects a job from the drop down, find the corresponding job in the jobs table that has the same "rank_id". That, I'm assuming, would allow the site to gather the "User", "Rank", "1st Requirement", "2nd Requirement", "3rd Requirement", and "Salary" info (all of which are contained in the members and jobs tables), and then insert that info into the appropriate fields in the workorders table, so that the info will then post to the site.
At that point all I would need to worry about are the "Date" and "Due By" columns - the "date" being automatically generated as the current date when the form is submitted, and the "due by" being automatically calculated as the current date plus 30 days.
I hope that's a more helpful explanation, and not too confusing.
You will need to create an OnSubmit event for the form which will return false inside the javascript function. The function will then need to add the content to the page. I would give more detailed code if you provided a layout.
Related
I didn't know how to give title to this but I have the following database:
accidentDetain(id, location, weather_conditions desc (and few more columns));
weatherConditions(id, title)
acc_weat_cond(id, wc_id, ad_id)
wc_id = weatherConditions ID, ad_id = accidentDetain ID
Now the situation is the user can store multiple weather conditions such as (rain, wet, snow Ice Fog etc)
Let's say user chooses 3 out of those 6 options and those will be stored in acc_weat_cond table, with accident Detail id and weather conditions id.
After saving, the user decided to change and to unchecked one of the option and then presses the save button. The issue is, there are 3 records already stored into acc_weat_cond table how would I would change and make them to two records.
Will I have to delete the first records from the database and then store again newly checked options? Or is there any easier way doing the above mentioned situation.
One last option is that I violate the role of database normalization and stored directly in the accidentDetails table and separate the values with a comma.
Feel free to ask if any more information is required...
I would have an <input type='hidden'name='checkedflds' value='1,2,3' />-field which contained the values that were checked before the user updated. Then after postback, you can compare the new list against this and will easily see what additions he made and which elements he removed...
I would call all of the options and compare to what is checked, and delete what you need. If you store it on the form, then there is a potential for out of date data.
I have a semi-complex database with multiple tables (3) that I'd like to post data to.
Rules of database
Each experiment (experiment table) can have multiple varibles associated with it (1 to many)
Each variable (variable table) can have multiple values (value table) (1 to many).
Sample DB Structure
experiment table
exprid (pk - auto_increment)
pagetype
pagename
expresult
variable table
varid (pk - auto_increment)
image
varresult
exprid (fk)
value table
valueid (pk - auto_increment)
image
valueresult
varid (fk)
I'm setting up a form that accepts inputs that will post to the appropriate tables, however I am having a hard time understanding how I can get this to work properly.
Here's essentially what I'd like to do:
User enters experiment details
User enters details for variable 1 (that info is associated with the experiment)
User enters details for value 1 (that info is associated with variable 1)
user submits value 1 to value table
User enters details for value 2 (that info is associated with variable 1)
user submits value 2 to value table
user is finished entering values for variable 1
User creates new variable in order to enter new values
Repeat steps 2-6
Ultimately, I am unsure how to:
a) post to the appropriate tables
b) ensure the visitor does not have to enter the experiment details once a value or variable is submitted
The ask:
It would be great if someone can help me understand the logic that goes into something like this. I really don't even know where to start because all of the forms I've built so far require me to only post to 1 table. So written logic would be helpful.
Any links to posts about this topic or articles online, any instructions on how to tackle or even sample code would be helpful. At this point, I think anything would be helpful if I can just get an idea of where to start.
So after each submit (via ajax request) you have to extend your list of fields.
If you're using jQuery I would suggest to have a look at it's ajax methods: http://api.jquery.com/jQuery.ajax/
When the data is submitted dynamically add your fields, there are dozens of tutorials, like: http://www.infotuts.com/dynamically-add-input-fields-to-form-jquery/
That's all, so in the end you'll have multiple requests which always store your new added data and skip the reload of the pages, as ajax is done in the background.
I am new and trying to make a simple website for a project. I have to pages, add and view hobbies. User needs to be able to add 1 or more hobbies and store it in a database and to retrieve it in another page, i have listed what i plan to do below.
How do i make it such that I am able to store multiple hobbies for users in the database?
Using MySQL, HTML, PHP, Dreamweaver
Assume: User has been created, user has been logged in and all user related database coding has been done. More than 1 user exists, all users are to have a few hobbies each.
Database
User table: UserId, Username, HobbyId
Hobby table: HobbyId, HobbyName, HobbyDaysAWeek
1 user can have 0 or more Hobbies.
Add hobby page
dropdownlist (binds list of hobbies from hobby table)
textbox (for user to enter how many days a week he spends engaging in that hobby)
add button (displays value in dropdownlist and textbox in a table)
table (Hobby and daysAWeek will be shown here, with a delete icon to delete it)
submit button(saves hobby & days a week & username into database)
View hobby page
Displays user's hobby & days a week in a table.
Thanks for helping! And please provide simple and bare minimum coding as i am new!
Well, nobody posted an answer but my question was answered in the comments so..
Start by adding a 3rd table with UserId and HobbyId – Dagon
You're storing the relationship between, not a relationship. So think of it like you have two things and you want to remember that they relate. Thus, a table with two columns, one with an identifier of one part, the other with identifier (ID) of the other part. Pull them together with the data about each part, you have information. Hence, you've stored the relationship. It's like metadata, really. It's usually pretty efficient. - Jared Farrish
Thanks guys!
I am making a mysql/php project and in one form, the specs require dynamic fields in a way that you have an initial selectbox with a value from a lookup table that describe job unions. Depending on the selected value, it will spawn (probably via reflection) different fields.
For example, I have 2 associations with ids 1 and 2. If the user selects union #1, then the fields would be first name, last name, phone, address. If the user selects union #2 then the fields would be mobile, email, im name, "enroll now?"(checkbox).
Now, this might occur often, because the total of unions are more than 10 and specs require it to be flexible.
What I thought is this:
form loads up the fields of the first lookup (jobunions)
user selects the job union, and the value of the selectbox is the name of another table, for example LK_TABLE_2
The reflection examines the LK_TABLE_2 fields and retrieves/renders the fields below the selectbox of step 1.
I need your opinion on whether this business logic is acceptable (is there a pattern I could use?), if not anything to suggest and if it's doable how to store the filled data into the user preferences table.
Any insight would do.
Update: here is a schema (pdf) of what I am trying to do
https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B_vptVa0K8J2YjBjMGJmZDgtYzUxZi00ZTE5LTgxZjgtOTNlMjQ5OGM3ZTY1&hl=en_US
I am closing this question, because of the project that was terminated, and further more I don't work in the specific company anymore (over half a year ago).
We jumped to a more nosql solution before this happened and it was working fine... until termination.
I have read other answers on this (or at least near to this) subject but I couldn't get a clear view of it so I'm asking for help again.
I have a complex dynamic HTML form that I would like to submit to database using PHP. The form is split into multiple tabs and in each tab I got checkboxes that trigger other parts of the form. Example: at a point in my form I got a checkbox group that has options of: "hotel" and "restaurant". If I check hotels, I get another part of the form displayed, specific for "hotels". Same thing for "restaurant". So it's very dynamic here and I don't know which would be the best approach for storing every form field in database. Because it could contain 15 fields or 20, depending on the selection. Any example would be appreciated as I'm not that advanced with database design.
Thank you!
So it's very dynamic here and I don't
know which would be the best approach
for storing every form field in
database.
I apologise if I have misunderstood you here but I believe that you should design the database according to the data and not the form. It is difficult to comment without knowing the exact details of your situation so here is an example:
If you usually dump all the data from a form into a single table, but because sometimes this will involve submitting 5 values and other times this will involve submitting 10 and so you are unsure how many columns your table should have, then I think the problem is in the database design.
Work out what pieces of data are dependent on other pieces of data. For example, you mention checking "hotel" might open up more fields specific to that choice. Let's assume this involves things like "en-suite", "bed type" etc. Then you should have 3 tables, a registration table (assuming the user is using the form to buy these services), a hotel table and a registration_hotel table. The registration table will record a number of details specific to the registration only such as the customer's name and a unique id number. The hotel table will hold information specific to the hotel only, such as how many rooms have en-suite. The registration_hotel table will hold details specific to that registration at that hotel. You might want a column of type bool to record whether the user requested "en-suite".
When submitting the form, check which pieces the user entered with if(isset($_POST['hotel']) && !empty($_POST['hotel'])). Then only send stuff to the registration_hotel table if that condition is true.
If this design results in making too many separate calls to the database, you might want to look into transactions which will help you to manage the speed and security of these calls.
If you can post in a specific example of something you don't know how to do, that would be useful.
You didn't specify how you can manage this dynamic form. Can you edit it's PHP/HTML source? One great thing would be if you can label your different variables like hotel[], restaurant[], etc.
If your submitted form is clear enough (i mean semantically correctly structured) you can store the whole submitted form serialized.
Note: this method only working when you don't need to search for specific items in your database.
Edit: maybe i'm misunderstood your problem.
You can create a 'metadata' table like this:
form_id | option_name | option_value
---------------------------------------
1 | hotel | true
1 | restaurant | false