Save variable on a click

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Save variable on a click

    I have a menu made up of images where users can click an image to load the
    next page. I want each image to send a unique id number to the page the
    user loads. Based on this id number, the page that will be loaded will
    display something different.

    Since I'm not using a form to post data, I decided to save the id number as
    a session variable. The loaded page will read the variable when determining
    what to load. The problem I'm encountering is where to put the code to get
    the first page to save the id number (I know how to save and retrieve
    session variables, so that's not an issue).

    I've tried putting the php script inside the onclick attribute of the link,
    but that didn't work. Does anyone know how I can do this, or know a better
    way? Thanks.


    --
    John Victor


    John Victor Guest

  2. Similar Questions and Discussions

    1. Set session variable on image click
      Hi there guys, Having a problem...I want to set a language session variable when a user clicks on a flag which is in an image map on the index...
    2. Don't want to right click on a PDF link to save it!!!!
      Hi can any one help me to download a .pdf file with out doing save as but just to click on it and it will automatically go to the Save dialog box!!!...
    3. Save variable value to file from movie...
      Hi, I've got a movie where user inputs text and some data. And now i want save it to the disc to a specific folder. How i can do this?? Any help,...
    4. I need to save a class object in a Session variable. Good? Bad?
      Hi, I am in a situation where I am forced into passing a class object around between a bunch of pages. The only way that I can figure out how to...
    5. on click of a link button should first save the data and then open a new browser
      Hi, A page consists of a link button. Clicking this link button should first save data in the database. If the data is saved correctly then it...
  3. #2

    Default Re: Save variable on a click

    On Sun, 01 Aug 2004 07:32:31 GMT, "John Victor" <wiegeabo@pacbell.net>
    wrote:
    >I have a menu made up of images where users can click an image to load the
    >next page. I want each image to send a unique id number to the page the
    >user loads. Based on this id number, the page that will be loaded will
    >display something different.
    >
    >Since I'm not using a form to post data, I decided to save the id number as
    >a session variable. The loaded page will read the variable when determining
    >what to load. The problem I'm encountering is where to put the code to get
    >the first page to save the id number (I know how to save and retrieve
    >session variables, so that's not an issue).
    >
    >I've tried putting the php script inside the onclick attribute of the link,
    >but that didn't work. Does anyone know how I can do this, or know a better
    >way? Thanks.
    You don't need a form to send data to the server. And sessions are
    dealt with solely on server-side. So the problem is, how to tell your
    script which image the user clicked on. You can use $_GET: Meaning,
    append a ?name=value to the links of your images. Name could be
    anything you want the variable to be called, so you can access it via
    $_GET['name'] in PHP. Value is some unique identifier to determine
    which image was clicked (it could be as simple as the image file name,
    or something you concoct yourself).

    Remember, the key to writing successful sites is communication: You
    have to find viable ways to have your web pages communicate with your
    PHP back-end. $_GET and $_POST are the two most popular ways, certain
    $_SERVER variables (i.e. PHP_SELF, PATH_INFO, etc) are another way.
    Create a file, name it whatever you want, and put the following code
    in there to help you see what goes between the browser and PHP:

    <?
    phpinfo();
    ?>

    Happy coding.
    eclipsboi Guest

  4. #3

    Default Re: Save variable on a click

    eclipsboi wrote:
    > You don't need a form to send data to the server. And sessions are
    > dealt with solely on server-side. So the problem is, how to tell your
    > script which image the user clicked on. You can use $_GET: Meaning,
    > append a ?name=value to the links of your images. Name could be
    > anything you want the variable to be called, so you can access it via
    > $_GET['name'] in PHP. Value is some unique identifier to determine
    > which image was clicked (it could be as simple as the image file name,
    > or something you concoct yourself).
    >
    > Remember, the key to writing successful sites is communication: You
    > have to find viable ways to have your web pages communicate with your
    > PHP back-end. $_GET and $_POST are the two most popular ways, certain
    > $_SERVER variables (i.e. PHP_SELF, PATH_INFO, etc) are another way.
    > Create a file, name it whatever you want, and put the following code
    > in there to help you see what goes between the browser and PHP:
    >
    > <?
    > phpinfo();
    > ?>
    >
    > Happy coding.
    Indeed, PHP is server side, so once it's outputted, you can't change the
    vars anymore.

    You could try to use a database in order to stock the meaning of the
    picture's IDs. The big part of the script will of course populating the
    database, but it's i think one of the best ways to do so.

    HTH,
    Sebastian
    Sebastian Lauwers Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139