SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing Parameter over more than one page / into a form?

    Is this possible ...

    I have a list of jokes, each with its own ID (jokeid) and next to each joke it says EMAIL JOKE. If they click on the hyperlink, it goes to the email joke page using: http://jokes.com/emailjokes.php?jokeid=xxxx ... xxxx = jokeid. (i.e. http://jokes.com/emailjokes.php?jokeid=1234)

    On the email joke page then it will use the jokeid, go into the database, and display the joke once again, and then have a email form below it. The user would submit their email address and when they click SUBMIT, the joke would be emailed to them. But what I'm having trouble with, and there may be an easier solution, is passing the same jokeid parameter to another page after it has already been passed once.

    Is there a way to get the URL parameter and put it in a hidden field or something in the HTML form, and then when the form is submitted, it would go with the form????

  2. #2
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your last idea is exactly how i've done it in the past..
    if its an array you'll have to recreate the array(in my experience anyways).
    it would go something like this
    first_page.php
    here you'll have your jokes, probably with checkboxes or radiobuttons..
    name them something like index[] if you want them to be able to selet more than one

    then on page_2

    assuming you are using method "post" for your form, just do

    foreach($_POST['index'] as $key) {
    echo "<input type=\"hidden\" name=\"index[]\" value=\"$key\" />";
    }

    thats if you have an array of jokes
    if you have only a single joke, just create one hidden form element to hold the value of the joke that they picked ont he previous page.. make sure that this hidden form element is within the form that will get passed to the next page.

    other methods would be use cookies, sessions, or a database..
    if you want some examples on that, let me know

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay ... maybe I'm doing this wrong ...

    anyways, when the user clicks on EMAIL joke and it sends the URL parameter, jokeid like so ...

    http://jokes.com/emailjokes.php?jokeid=1234

    then I tried to do this in the form...

    <input type="hidden" id="joke_id" value=$jokeid>

    then in the email script, i have a line ...

    $sql_query = "SELECT * FROM jokes WHERE jokenumber like $joke_id";

    but it keeps showing

    "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource"

    any suggestions????

  4. #4
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Birmingham UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe try using:


    $query = mysql_query($sql_query)
    $row = mysql_fetch_assoc($query);
    echo "$row[columnname]"; //Or whatever your doing with it.

    Shouldn't it be $jokeid in the sql_query?

  5. #5
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I have in the email script (which is called when the user clicks on the SUBMIT button the email fomr)

    $sql_query = "SELECT * FROM jokes WHERE jokenumber like $joke_id";

    //store the SQL query in the result variable
    $result = mysql_query($sql_query);
    if(mysql_num_rows($result))
    {
    //output as long as there are still available fields
    while($row = mysql_fetch_row($result))
    {

    echo "$row[1]<BR><BR><BR>";

    --------------------------------------------------------
    Any suggestions?

  6. #6
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Birmingham UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not sure what you problem is. Could you be a little more specific? Im kind of lost.

    Are you having problems mailing the url? Could you show us the entire email script?

  7. #7
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fixed!!! mwolfe rocks!


Bookmarks

Posting Permissions

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