Select Lists into MYSQL
Posted on
16th Feb 2014 07:03 pm by
admin
Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but hit a snag.
I have 2 list boxes, that I use to move items left to right. When I click submit I want to load the items selected into MySQL. Is anyone able to help please? I can do the insert into MySQL (i think), but i cant work out how to get the values into a variable that PHP can use to submit.
Then to make it more complicated, once I have it working for 1 list, I ideally wany about 10 lists on the page (with only 1 submit box). I am lost.
Thanks
greg
Code: This is my OPTION.js file
var selectedList;
var availableList;
function createListObjects(){
availableList = document.getElementById("availableOptions");
selectedList = document.getElementById("selectedOptions");
}
function delAttribute(){
var selIndex = selectedList.selectedIndex;
if(selIndex < 0)
return;
availableList.appendChild(selectedList.options.item(selIndex))
selectNone(selectedList,availableList);
setSize(availableList,selectedList);
}
function addAttribute(){
var addIndex = availableList.selectedIndex;
if(addIndex < 0)
return;
selectedList.appendChild(availableList.options.item(addIndex));
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function delAll(){
var len = selectedList.length -1;
for(i=len; i>=0; i--){
availableList.appendChild(selectedList.item(i));
}
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function addAll(){
var len = availableList.length -1;
for(i=len; i>=0; i--){
selectedList.appendChild(availableList.item(i));
}
selectNone(selectedList,availableList);
setSize(selectedList,availableList);
}
function selectNone(list1,list2){
list1.selectedIndex = -1;
list2.selectedIndex = -1;
addIndex = -1;
selIndex = -1;
}
function setSize(list1,list2){
list1.size = getSize(list1);
list2.size = getSize(list2);
}
function getSize(list){
/* Mozilla ignores whitespace, IE doesn't - count the elements in the list */
var len = list.childNodes.length;
var nsLen = 0;
//nodeType returns 1 for elements
for(i=0; i<len; i++){
if(list.childNodes.item(i).nodeType==1)
nsLen++;
}
if(nsLen<2)
return 2;
else
return nsLen;
}
function showSelected(){
var optionList = document.getElementById("selectedOptions").options;
var data = '';
var len = optionList.length;
for(i=0; i<len; i++){
if(i>0)
data += ',';
data += optionList.item(i).value;
}
alert(data);
}
Code: This is my edit.php file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="option.js"></script>
</head>
<body onload="createListObjects()">
<?php
echo" <select name="selectedOptions[]" id="selectedOptions" multiple="true"> "; //start the select box
echo "<option value="1">Cat</option>n"; //and place it in the select
echo "<option value="2">Dog</option>n"; //and place it in the select
echo "</select>"; //close the select
?>
<button onclick="addAttribute()"><</button>
<button onclick="addAll()"><<<</button>
<button onclick="delAttribute()">></button>
<button onclick="delAll()">>>></button> </td>
<?php
echo" <select name="availableOptions" id="availableOptions" multiple="true"> "; //start the select box
echo "<option value="3">pig</option>n"; //and place it in the select
echo "</select>"; //close the select
?>
<tr>
<td colspan="2"><button
onclick="showSelected()">
Submit</button> </td>
</tr>
</body>
</html>
Code: <html><body>
<?php
$data = $_POST['selectedoptions'];
I AM LOST HERE
echo "Data Inserted!";
?>
</body></html>
No comments posted yet
Your Answer:
Login to answer
161
9
Other forums
Appending GET data with form submition
Okay, what I'm trying to do is to use a form to append an already existing GET data string.
I
Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that
Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I wa
how to hide input fields on selection screen using variant attribute
Hello all,
I want to know how to hide input fields on selection screen using variant attr
Need help with cin setw
I made a program here is my code:
#include
#include
#i
noob question
i traying to do a php form with auto replay for both(me and the user who send me a mail),
a u
Why does this file not return file names that start with numbers?
This file returns a list of filenames to help populate a drop down in my form. For some reason it ig
check if value exists
I have googled this for a while and I am getting lots of different results. Is there a standard meth
this code is strange !
Hi i got this code from the web.. It checks for live and dead socks
It is working perfectly on my
need help in creating captcha
hi i have a problem creating captcha system. i create some basic script for image displaying but it