SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing Variables in a Query String

    Reading Sitepoints' book on PHP/SQL and am a bit mystified why I am not able to pass the variable in the query string from welcome1.html to welcome1.php and have it display on the page - all I get is a blank page. Does this have anything to do with my file structure?

    Thanxs in Advance for the HELP!!!

    THE CODE FOR welcome1.html:

    <html>
    <head>
    <title></title>
    </head>
    <body>

    <a href="welcome1.php?name=Doug">HI, I am Doug</a>
    </body>
    </html>

    THE LOCATION OF the welcome1.html file

    C:\Inetpub\wwwroot\test\lesson3\welcome1.html


    THE CODE FOR welcome1.php:


    <html>
    <head>
    <title></title>
    </head>
    <body>

    <?php
    $name = $_GET['name'];
    echo("Welcome to our website, $name!");
    ?>

    </body>
    </html>


    THE INFORMATION BEING PASSED IN MY URL BOX to welcome1.php:

    file:///C:/Inetpub/wwwroot/test/lesson3/welcome1.php?name=Doug

    I should see "Welcome to our website Doug!" on the php page. Right? The variable is being passed in the query string(see above)! Anyways, little bit confused with what is wrong and am just new to this stuff.

    Thanks for the help!

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me know if this is the wrong assumption but from your posted url it looks like you arent using a webserver to do this. If your doing this on a local machine then your url should look more like this:
    http://localhost/test/lesson3/welcome1.php?name=Doug
    It appears your just trying to do this with file browsing and bypassing the webserver.
    Erh

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mandibal, thanks for the response!. Yes, I have a server set up on my computer and am doing this locally. I copied and pasted your url

    http://localhost/test/lesson3/welcome1.php?name=Doug

    into my link on the welcome1.html page. Still doesn't work!. I had both files in the same folder so I was just using relative addressing, as you can tell from my code above. Not sure what I am doing wrong! The instructions in the sitepoint book seem pretty straightforward. Hmmm anymore suggestions. Thanks for the help LAST RADIUS

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2003
    Location
    New York, NY
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds strange, but I think you're doing something wrong somewhere. Some things to keep in mind:

    For this to work, the PHP file needs to be parsed by PHP. Therefore, accessing the script via windows explorer (which is what happens when you put the file://path/to/file.php format into IE) will not work. You need to access it via a TCP connection to your web server. Try http://255.255.255.0/test/lesson3/we....php?name=Doug where 255.255.255.0 is the IP address of your machine (you'll have to find out the IP address, it won't be 255.255...). To find your ip you can open up a dos prompt and type 'netstat'.
    So I says to him, I says, Hey! Llama! How about a little something, you know, for the effort, you know?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, it doesn't work when I place my files in the wwwroot folder and then via windows explorer open the html file and click on the link to the php file; however, if I open up the html file in Dreamweaver and then press Ctrl + F12 to open it in my primary browser, the code will work as outlined in the book.

    When I open the html page directly from the browser window using windows explorer(wwwroot folder) and click on the link, I am fed an empty php page with following address in the URL box:

    file:///C:/Inetpub/wwwroot/test/lesson3/welcome1.php?name=Doug

    However, when I open the html file in the Dreamweaver workspace and then open it (Ctrl + F12) via my primary browser and then click the link, I get the desired results. Now the url in the URL box reads (this is what Mandibal suggested I place in the box) the following address:


    http://localhost/test/lesson3/welcome1.php?name=Doug

    I assumed you could just open the files from inside the root folder and they would work correctly. I am still not quite sure how this works, and why I cannot directly access my files without opening up Dreamweaver.

    Tom, I will try out your suggestions - but I am not to well versed in this stuff and never get to far off the beaten track (DOS ?).

    Any further suggestions to streamline the work process are appreciated.

    Thanks for all the suggestions and good luck!

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, just checked out the the process and everything is okay if place an absolute link on my html page pointing at the following url

    http://localhost/test/lesson3/welcome1.php?name=Doug

    I guess when I used relative addressing on the page (as is done in the sitepoint book) my code is not being parsed by PHP. I was just following the directions as exactly stated in the book, but I now see what you guys are getting at. Thanxs for the help, once again!!


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
  •