Forum Moderators: coopster
I wrote this data array in javascript, it is an automated 3 level dropdown menu. If i want to store the chosen options in a database..what code do i use?
As you might have noticed from my other post im not an PHP expert so any help or tips are appriciated.
Thanks a lot!
Dax
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[3] = "Påminnelse";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Inkasso";
arrItemsGrp1[4] = 1;
arrItems1[5] = "Inbetalning";
arrItemsGrp1[5] = 1;
arrItems1[6] = "Täckning";
arrItemsGrp1[6] = 2;
arrItems1[7] = "A.P.N.";
arrItemsGrp1[7] = 2;
arrItems1[8] = "Blackberry";
arrItemsGrp1[8] = 2;
arrItems1[0] = "Kontantkort";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Tjänster";
arrItemsGrp1[1] = 3;
arrItems1[2] = "Abg Byte";
arrItemsGrp1[2] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[21] = "Förfrågan";
arrItemsGrp2[21] = 0
arrItems2[22] = "Klagomål";
arrItemsGrp2[22] = 0
arrItems2[28] = "Tvist";
arrItemsGrp2[28] = 0
Which of your variables do you want to store and what will the table look like you are storing these variables in?
Is this something to allow you to look through the results, or is this just for the user to use as a default setting for something? As if this is for a default setting it may well be a lot easier to store the information as a cookie [php.net].
This data is to be entered by different people and is there only to b viewed by one with a mysql query.
The mysql table looks like this:
team works fine
agent works fine
cat1 = js array
cat2 = = js array
cat3 = = js array
The query to view the results is to be written later or perhaps not at all, the most important thing is to get the data input to work.
Will check the links 2:)
you can't do much with a javascript array on the server.
you will have to send the required data either as parameters in the query string of a HTTP GET or as form parameters in a HTTP POST.
that will make the data available to a php script on the server which is referred to either in the url of the GET or the form action attribute of the POST.
then you should look into php input parameter processing to retrieve your parameter values and then you can figure out how to store the data.
The mysql table looks like this:team works fine
agent works finecat1 = js array
cat2 = = js array
cat3 = = js array
How do your arrItems1 and arrItmesGrp1 fit into this table? As you have 5 columns and 2 bits of data you are inserting?
/*
assuming you have got your arrItems1 and arrItemsGrp1 into the
server and named then the same thing.
You also need to change <table_name> to the name of your table ;)
*/
$safeItems1 = [url=http://uk3.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($arrItems1);
$safeItemsGrp1 = mysql_real_escape_string($arrItemsGrp1);
$q = "INSERT INTO <table_name> (cat2, cat3) VALUES ($safeItems1, $safeItemsGRP1);";
$result = mysql_query($q);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
// do what ever you want with the results
if ([url=http://uk3.php.net/manual/en/function.get-magic-quotes-gpc.php]get_magic_quotes_gpc[/url]()) {
stripslashes($data);
}