the site i'll be refering to is
http://www.iaddesignandstudio.com/offline select the quote tab
if a person where to fill out this form and select more than one checkbox in either number 1 or number 3. how would i insert those selected values into a database so that when i retreive the information the user inputed or selected i can see which checkboxes he/she selected?
You can set your checkboxes to be in one array after the form is submitted by adding [] at the end of the name attribute like such:
<input type="checkbox" name="services[]" value="Podcasting Services" />
Podcasting Services
<input type="checkbox" name="services[]" value="Local Search" />Local Search
When the form is submitted, your $_POST['services'] variable will be an array containing all checked values. ex:
#var_dump($_POST['services']);
array(2) {
[0]=>
string(19) "Podcasting Services"
[1]=>
string(12) "Local Search"
}
Then you can do anything you want with that, wether it be sending an email or adding fields to the database using ether foreach() or implode() to loop through the values.
Hope this helps!
I would have separate fields in the database for them. Like in question 1, the posted form might submit $_POST['admycomp'] and $_POST['provideresource'] as having been checked. If so, insert a 1 into the database field admycomp or provideresource. That way you have recorded which fields they checked.
I would suggest storing the values in your database would be to use the SET datatype (eg: http://dev.mysql.com/doc/refman/5.0/en/set.html). This would store each of the checkbox values from a checkbox group in a single column in a storage-efficient way. You would probably need to use implode as mentioned above to create an SQL query to insert your set.
Related
I'm creating a CMS in which I have an overview of pages. I want the user to be able to mass delete these pages and so I have created a form in which each page has a checkbox with the pages database ID as value and name:
<input class="mass-delete-check" type="checkbox" name="<?=$page["id"]?>" value="<?=$page["id"]?>" id="<?=$page["id"]?>">
Now when I submit this form I need to get the values of the checkboxes that are actually checked and put them in an array I can go through to delete them. The thing here is that I will have to get checkbox values based on if they are checked and not on their name because I can't know all names.
Does anyone have a solution to this?
Use the same name for all checkboxes. So after submiting you will have array with page IDs to delete.
<input class="mass-delete-check" type="checkbox" name="delete_pages[]" value="<?=$page["id"]?>" id="<?=$page["id"]?>">
After submit you would get array of IDs with $_POST['delete_pages'], which contains actual page IDs what you need to delete.
Sorry if this is a stupid question but im really not sure how to tackle this, perhaps im overthinking. I need to retrieve both the name attributes value and the value attributes value. Have a look at img below:
echo'<input type="radio" name="'.$eventId[].'" value="'.$team1.'">';
The name contains the event_id and the value contains user selection. I need the name Ids value to insert event Id into db along with user selection.
I know how to retrieve the rad value attribute but not sure about the name, maybe Im overthinking it or need to change my logic. Any ideas?
If user select Australia radio button than in PHP you will get value 'Australia' but you want the value 'Australia_80' to store in db. Change all your radio button values and names like
<input type="radio" value="Australia_80" name="getRadio">
<input type="radio" value="Canada_81" name="getRadio">
Let's say I have a simple form, with a select combobox and a table that has a checkbox for each row, to choose the rows you want.
Now, on the server-side, I need to associate all the items selected from the table (using the checkbox for each row), with the item selected in the combobox.
I know the value in the combobox will be submitted with the form, but how can I send all the selected elements from the table? do I have to use AJAX or something? or is it possible to do it via POST/GET?
The form needs to enclose (be an anscestor of) both the table and the combo box.
The table row checkboxes should all look like
<input type="checkbox" name="rows[]" value="ROW ID"/>
And then on the server side you'll get, in addition to the combobox value, $_POST['rows'] as an array containing the ids of the checked rows.
Can you please enlighten me and give some ideas!
I can view my data from the database and insert a data into my DB.
Now all i want is to have a checkbox in each field, if i SELECT all my data and view it in a table, I will choose or check the field that i want to edit or to delete and click the button to pass the selected field into my edit form..
So how can i pass the value of the checkbox to the edit button?
When you post data to server if check box is clicked then value of check box is posted to server and you can find it in post data by its name, for e.g.
<input type="checkbox" value="1" name="chkEmail" />
in php you can get it this way
$_POST['chkEmail']
so on server side you can solve your problem like this
if(isset($_POST['chkEmail']))
updateEmail();
and do this for your every property, you can update each column with single query, or you can build query for update.
I'm trying to create a small web app that is used to remove items from a MySQL table. It just shows the items in a HTML table and for each item a button [delete]:
item_1 [delete]
item_2 [delete]
...
item_N [delete]
To achieve this, I dynamically generate the table via PHP into a HTML form. This form has then obviously N [delete]-buttons. The form should use the POST-method for transfering data.
For the deletion I wanted to submit the ID (primary key in the MySQL table) of the corresponding item to the executing php skript. So I introduced hidden fields (all these fields have the name='ID' that store the ID of the corresponding item.
However, when pressing an arbitrary [delete], it seems to submit always just the last ID (i.e. the value of the last ID hidden field).
Is there any way to submit just the ID field of the corresponding item without using multiple forms? Or is it possible to submit data from multiple forms with just one submit-button? Or should I even choose any completly different way?
The point why I want to do it in just one single form is that there are some "global" parameters that shall not be placed next to each item, but just once for the whole table.
<input type="submit" name="delete[1]" value="delete">
if (isset($_POST['delete'])) $id=key($_POST['delete']);
it seems to submit always just the last ID
It submits all of them, but since the name doesn't end with [], PHP discards all by the last.
Is there any way to submit just the ID field of the corresponding item without using multiple forms?
No. At least not without some unfortunate JavaScript. All (non-disabled) hidden inputs (with names and values) will be successful. You can't limit based on proximity to a clicked input element.
If I understand your goals correctly, you have two main options.
Put one form per row (in the cell with the delete button)
Encode the id value into the name of the submit button
You could get rid of the hidden fields and name your submit buttons like this:
<input type="submit" name="delete[1]" />
<input type="submit" name="delete[2]" />
<input type="submit" name="delete[3]" />
and then
<?php
if (isset($_POST['delete'])) {
$toDeleteId = key($_POST['delete']);
}