How to transfer variables from a .php script to an .html page that will display the results.

Discussion in 'Javascript' started by danubian@hotmail.com, Oct 28, 2004.

  1. Guest

    Hi,

    I'm a newbie in php/mysql programming,really am.
    I'm working on a web-site that allows registration and posterior
    logging in. Already registered user logs in with valid username and
    password. Username and password are validated against a MySQL database
    of personal data that contains these fields among others.
    This is done by means of a PHP script that redirects to a "page2.html"
    (if user and password non-existent) OR it redirects to a
    "page3.html",if username and password exist and match in the database.
    Following is part of the code:

    <?php
    function RedirectURL($url)
    { // This calls javascript
    $redir = "<script language=\"javascript\">location.href=\"$url\"</script>\n";
    return $redir;
    }
    ?> // got this function from the groups. thanks.

    <?php
    ..
    ..
    ..
    $query = "SELECT password FROM all_pers_data WHERE username =
    '$loginID' ";

    $result = mysql_query($query) or die
    (RedirectURL('http://xxx.xxx.xxx.xxx:XXXX/ / /page2.html'));
    $numentries = mysql_numrows($result); //Numero de filas
    returned. mysql_close($link);

    $correct_username = $loginID;
    $correct_password = mysql_result($result,0,"password"); //assumming
    there is only one match...
    if (strcasecmp($correct_username,$loginID) ||
    strcasecmp($correct_password,$loginPW) ) {
    die(RedirectURL('http://xxx.xxx.xxx.xxx:XXXX/ / /page2.html'));
    //loginID or password that do not match
    }
    else {
    die(RedirectURL('http://xxx.xxx.xxx.xxx:XXXX/ /
    /page3.html'));//ASSERT, print out info in .html page.
    }
    ..
    ..
    ..

    ?>

    My question is: how can I transfer the variable "$result" from my PHP
    to the .html pages, so that I'm able to print out the info for the
    existent user through page3.html. In other words, i would like to
    re-use "$result" from the php/mysql query; this, in order to display
    information about the successfully logged in user.

    Any help or suggestions i will appreciate a lot. Thanks.

    Ivan
     
    , Oct 28, 2004
    #1
    1. Advertising

  2. Grant Wagner Guest

    Re: How to transfer variables from a .php script to an .html page thatwill display the results.

    wrote:

    > My question is: how can I transfer the variable "$result" from my PHP
    > to the .html pages, so that I'm able to print out the info for the
    > existent user through page3.html. In other words, i would like to
    > re-use "$result" from the php/mysql query; this, in order to display
    > information about the successfully logged in user.
    >
    > Any help or suggestions i will appreciate a lot. Thanks.


    <url: http://jibbering.com/faq/#FAQ4_18 />

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Oct 28, 2004
    #2
    1. Advertising

  3. Pedro Graca Guest

    ["Followup-To:" header set to comp.lang.php.]
    wrote:
    [snip]
    > My question is: how can I transfer the variable "$result" from my PHP
    > to the .html pages, so that I'm able to print out the info for the
    > existent user through page3.html. In other words, i would like to
    > re-use "$result" from the php/mysql query; this, in order to display
    > information about the successfully logged in user.
    >
    > Any help or suggestions i will appreciate a lot. Thanks.


    Use session variables: http://www.php.net/session

    When you know the $result save it in a session variable

    $_SESSION['SQLResult'] = $result;

    and, afterwards, when you need the same result use the value saved in
    the session variable

    echo 'Saved result is: ', $_SESSION['SQLResult'];

    Don't forget to start the session support in *every* page that uses the
    $_SESSION array
    --
    USENET would be a better place if everybody read: | to mail me: simply |
    http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
    http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
    http://www.expita.com/nomime.html | and *NO* attachments. |
     
    Pedro Graca, Oct 28, 2004
    #3
  4. .oO()

    > function RedirectURL($url)
    > { // This calls javascript
    > $redir = "<script language=\"javascript\">location.href=\"$url\"</script>\n";
    > return $redir;
    > }


    header("Location: $url");

    http://www.php.net/header

    Micha
     
    Michael Fesser, Oct 28, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stu
    Replies:
    2
    Views:
    822
    Rob McAninch
    Apr 6, 2004
  2. Rajive Narain
    Replies:
    0
    Views:
    2,091
    Rajive Narain
    Sep 18, 2009
  3. Asra

    display php results in a div

    Asra, Aug 20, 2004, in forum: Javascript
    Replies:
    0
    Views:
    83
  4. Asra
    Replies:
    2
    Views:
    114
    Csaba Gabor
    Aug 20, 2004
  5. bpascal123

    c cgi script display results below html form

    bpascal123, Mar 17, 2013, in forum: C Programming
    Replies:
    3
    Views:
    308
    Joachim Schmitz
    Mar 19, 2013
Loading...

Share This Page