Jump to content

Javascript variables to php-mysql


dannybrazil

Recommended Posts

Hello

Im using javascript and cookies to send to another page in my site some variables

 

In the other page i recieve them like that :

<script language="JavaScript"> 
if (widget_array != ""){
for (i=1; i < widget_array.length; i++){
document.write("<h3>" + widget_array[i] + "</h3>");
}//ends diplay FOR
}//ends widget display

if(ninja_array != ""){
for (i=1; i < ninja_array.length; i++){
document.write("<h3>" + ninja_array[i] + "</h3>");
}//ends FOR
}//ends ninja display
</script> 

 

Now my question is ....(and this is the php - sql question)

how can i make the variable the i passed to stay a variable , e.g.

 

variable page 1:

id=123

*i entered the number 123 into the cookie

variable page 2:

now this page will show me ALL the array ( 123...134...156...etc...)

but i dont want it to print it on the screen i just want to get variables that i can use php-mysql

e.g. $id=123

in order to print the specific data from my data base

 

hope u got it....

 

Danny

Link to comment
https://forums.phpfreaks.com/topic/173103-javascript-variables-to-php-mysql/
Share on other sites

use a hidden input and use a document.GetElementById('hidden').value = javascriptVar;

(use "hidden" as the inputs name attribute)

then use:

document.forms('id').submit;

to submit it (make sure the forms method="POST")

then to access it via the new page is $_POST['hidden']

then do whatever you want with the php var with SQL.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.