I want to make a form in php where there will be two categories. One for the Student profile details and another for the student's
marks details. Now the main problem is all this will be in one single form means in one page and the categories like student details will be save in student detail table of the database and the marks will be save in another database called marks database. I also need CRUD for these two categories.So how to do that?
Any suggestion and help will be highly appreciable.
Well there is no direct link between a form and a database table, so what is your problem?
Why don't you do the mysql_query() on each table one after another when you handle the form post?
You can build your form like this in order to separate the tables:
<input type="text" name="data[student][name]" />
<input type="text" name="data[category][name]" />
you PHP script then goes through the data and save it in the corresponding tables:
foreach($_POST['data'] as $table=>$row){
// do your insert statemnet here (don't foregt to escape the Parameters!)
}
Related
I have a SQL Database where the users can create a ticket then update the ticket if need be. This all works and the user can view the updated field in the , but what I would to achieve is to display the newly updated field in a different textarea field but not be able to edit it and only edit a new textarea field. Once saved and the user needs to update it again it needs to then display the 2 uneditable textfields and display new textfield to update.
Here is my code what i have at the moment:
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>Description</label>
<textarea name="descriptionfield" class="form-control" required="required" placeholder="Enter Description"><?php echo $description; ?></textarea>
</div>
So with this code I can update and delete but only displays in the same textarea.
Can someone point me in the right direction to achieve this?
Hoping what I explained makes sense.
Thanks
Something like the below image
So you are only able to update and delete a textarea but you want to show the original one and a new empty text area after they submit, then if they update that one, the original one and second one show all while allowing a new textfield to be there?
You aren't creating the text-boxes, submitting queries, and fetching results in a way the allows you to do that.
What you need to do is:
In your general application you will need 2 things, the empty text area field for the which you already have. An empty div area where you could display the old text areas.
In your database you need to add another table because you you will basically be joining these child text area updates updates. new table: textareachildren.
When somebody submits a ticket, that text area information should go into your first table where the info is going which is already happening. Now I'm assuming your table for those posts has a primary ID correct? so lets say we just put a ticket in and the ID is 1. Here is where #Padmanabhan is trying to find out, when the ticket is submitted the page is refreshed correct? and it shows that ticket they just submitted?
Now they want to edit that ticket's text area, I assume you already are pulling in the ticket by it's ID. Since you said they could already edit/update but it just shows the value they submitted. It looks by your picture that theres a note added and new note section. OK so thats good, so within that function where they could update the ticket text area field, a few important things need to happen. Once they click update, you need to run a sql query to input this new textarea value into the textareachildren table. within that table there should be 3 columns, the primary ID of the new items in there, the value of the textarea field, and third the important the connecting_ID which is the same value of the ID of the original ticket ID. this is how they will be connected and you could display those historical text areas.
Now go back to your original query that displays the ticket when they first submit, in there you need to also query by joining the the original ticket id with the connecting_ID of the new child textarea. The query will say ah yes, I am pulling this textarea value from the other table because my connecting_ID is 1 and it matches my 'parents' so I know I belong to them. Then just display that in the html within a new text area field that does not have the option to update/edit, since its probably a for loop for all those children that you want to show, you could add in the HTML textarea disabled readonly attributes, and even add classes to it so its like grayed out or something that shows you can't edit.
So to summarize every time somebody updates the text field you aren't changing that original value since you want to display that, you just add this new child textarea field value in a new table, when you query to show those old values to you just join them and display those historical textareas how ever you want.
I have a php/mysql application in which I have a database broadly having the following fields:
Employee No.
Employee Name
Year of Joining
Location
Job Profile
I am able to display the records using the SELECT statement with no problem.
Now, I want to be able to do the following and this is where I need your help/suggestion on how to achieve it:
Select a few records randomly (using a checkbox or any other method suggested here) from the list of records displayed.
Have a button saying "Processed" on the screen. When I click on the button, the screen should refresh and the records selected in Step 1 above should be moved to another database and only the unchecked records should now be displayed.
Please let me know your suggestion on how to do the above.
Thanks
TS
For this you can use the id of the record, to get the information of the particular record using another single select query, and also can update the record with the id of the record. (create an edit link and pass the id, on edit page get the information with the id and save it.)
<?php //your db connection and select query here ?>
<form action="process.php" method="post" enctype="multipart/form-data">
<?php
// loop starts here
echo "<input type='checkbox' name='ids[]' value='".$row["id"]."' />";
// loop ends here
?>
<input type="submit" name="process" value="Processed"/>
</form>
This will create the checkboxes and on the process.php page
you can get the ids your need to process and can move your data
to other table/db where you want and after than redirect back to
to the page where your code is.
I am learning Joomla-Development at the Moment and try to Set up a little component.
In the backend there is a form which consists of 2 fields. Field One should be saved into table 1 - Field 2 should be saved into table 2.
Field 1 is a text-field, which should be saved into table #__mycomponent_table1, field 2 is a Textarea, which should be saved into table #__mycomponent_table_2.
Table 1 already has got a overwritten store()-method. How can I Save the data of the field into another table?
Thanks in Advance :)
I solved it by overwriting the save-method in the model. You can call a second table and save the data after binding it.
You will need to override the save method in the controller - in that method you will need to save the data manually to the database.
Edit:
In your template file, add:
<?php echo JHtml::_('form.token'); ?>
<input type="hidden" name="option" value="com_yourcomponent" />
<input type="hidden" name="task" value="yourview.submit" />
This will ensure that your website calls the "submit" function in the controller.
i'm making a car info form in the admin panel. I want to add 6 images which would have the same id as the car info
form
car info selectors (x12)
file input (x6)
/form
2 separate tables (cars and images)
how do i give all the file inputs the same id as the car info?
i'm new to programming, but in my mind i have to use max(id) from the car table, add +1 and give it to all the input files carID when inserting them to the database. Is there and easier way to do this? or is my logic faulty?
If you are using mysqli in php then use the mysqli_insert_id function
http://www.php.net//manual/en/mysqli.insert-id.php
This gives you the id of the last record inserted.
You should never just use the max id. Entirely possible another record has been inserted by another user / process between your insert and you following inserts of dependent records.
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