Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[PLEASE HELP] Passing variable to new page

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
Hello,
I am having hard time passing the variable to the next page. May be you can help me. Let me explain:

I am using mySQL database to store information about images (ID, name, author, description, etc). I am pulling some of the information to create this (look at the example here: Now, I want a new window appear when user clicks on the image. I have achieved it with the following script:

echo &quot;<script language=\&quot;JavaScript\&quot;>&quot;;
echo&quot; function pop1() {&quot;;
echo&quot; window.open(\&quot;info.php?prod_id=$result[0]\&quot;); }&quot;; \\ $result[0] is variable that stores id of the image in database
echo &quot;</script>&quot;;

I am calling this function in the following manner: echo&quot;<img onclick=\&quot;pop1();\&quot;&quot;;

You can see the result if you click on the image. The new page opens up, BUT the id (product_id in this case) value is not passed to the next page correctly. If you click on the first or second image on the first page it shows that the ID is the same for both of them. However if you look at the source code you can see that the ids are assigned correctly. The same thing happens if you click on any image that says “no image available” (I am using different script to generate those). It seems that the script picks up and stores in the memory the value of an ID of the last image generated with the script (I don’t know if that make sense).

Oh, by the way the contents of info.php that I am calling in the script above are as following:

<?
$myid = $_GET['prod_id'];
echo&quot; Product ID: $myid<br>&quot;;
?>

What am I doing wrong? Can you help?
Thank you.
 
Have you tried passing the product_id as a parameter to the pop() function (i.e. pop(1))?
 
i see two mistakes:

first: i would'n use _ char in a querystring variable name

second: php is printing the result[0] variable value only once and in the wrong place. you're printing that value in the js function declaration so everytime you call that function, this function calles the next page and passes always the same value. i would type:

echo &quot;<script language=\&quot;JavaScript\&quot;>&quot;;
echo&quot; function pop1(id) {&quot;;
echo&quot; window.open(\&quot;info.php?prodid=\&quot; + id); }&quot;; \\ $result[0] is variable that stores id of the image in database
echo &quot;</script>&quot;;

then, within the mysqlquery result request loop:


echo&quot;<img onclick=\&quot;pop1($result[0]);\&quot;&quot;;

now you're printing the $result[0] value into every pop1 function call. this passes the $result[0] value to the js function, then the js function passes the value to the next page.
then type:

<?
$myid = $_GET['prodid']; // i supressed the _ char
echo&quot; Product ID: $myid<br>&quot;;
?>

i tried see your example at the adress you brought but that requests a username and password...
anyway, i hope this helps

replies to: fedebaseggio@hotmail.com

i have a doubt: did you check tha value of each $result[0]?? cause i usually cal $result a previous variable from wich i get $row[0]...
 
Thank you for your suggestions. I have solved the problem!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top