+ Reply to Thread
Results 1 to 7 of 7

Thread: php $_GET and echo error

  1. #1
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Question php $_GET and echo error

    Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/allofus/public_html/shows/all/index.php on line 17

    Code:
    <?php echo $txt['<?php ($_GET['host']);?>_show_title']; ?>
    I have

    webadress/index.php?host=britishnproud

    I want to echo the word 'britishnproud so that 'britishnproud_show_title' is echo'd from $txt on a separate file.


    I know this is possible, but I have tried many variations with no luck,
    any ideas please?

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,226

    Re: php $_GET and echo error

    PHP Code:
    <?php 
    $txt 
    $_GET['host']; //declare that $txt is the value of 'host' in the URI
    $txt .= "_show_title"//Now we append the text "_show_title" to the end of the current $txt using " .= "

    echo $txt//echo our current value of $txt. That's $_GET['host'] with "_show_title" appended to the end.

     
    ?>
    Is that what you're looking for?
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    xadrieth is offline x10Hosting Member xadrieth is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    62

    Re: php $_GET and echo error

    PHP Code:
    <?php
    echo $_GET['host'] . '_show_title';
    ?>
    this is probably the most simple way of getting what you want.
    Last edited by xadrieth; 07-02-2009 at 08:52 PM.

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,226

    Re: php $_GET and echo error

    It would, but I believe that $txt contains more data than just a blank variable, but I'm not sure.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  5. #5
    xadrieth is offline x10Hosting Member xadrieth is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    62

    Re: php $_GET and echo error

    O yea, fourallofus, when using the PHP tags, you can't create another instance of PHP with an instance of PHP. If your confused, just take a look at this example:
    PHP Code:
    <?php
    echo 'Welcome back ' . <?php $_GET['username']; ?> ;
    ?>
    The above will just not work.
    PHP Code:
    <?php
    echo 'Welcome back ' $_GET['username'];
    ?>
    The above works.

    And if you ever want to break from the PHP logic, you do it like this:
    PHP Code:
    <?php
    if (isset($_GET['username'])) {
    ?>
    <h1>Hi</h1>
    <?php
    }
    else {
    ?>
    <h1>Please Login</h1>
    <?php
    }
    ?>
    This might seem a bit confusing though for people who are new at PHP.
    Last edited by xadrieth; 07-03-2009 at 11:59 AM.

  6. #6
    glanceworld is offline x10Hosting Member glanceworld is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    13

  7. #7
    drf1229 is offline x10Hosting Member drf1229 is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    71

    Re: php $_GET and echo error

    Quote Originally Posted by xadrieth View Post
    O yea, fourallofus, when using the PHP tags, you can't create another instance of PHP with an instance of PHP. If your confused, just take a look at this example:
    PHP Code:
    <?php
    echo 'Welcome back ' . <?php $_GET['username']; ?> ;
    ?>
    The above will just not work.
    PHP Code:
    <?php
    echo 'Welcome back ' $_GET['username'];
    ?>
    The above works.

    And if you ever want to break from the PHP logic, you do it like this:
    PHP Code:
    <?php
    if (isset($_GET['username'])) {
    ?>
    <h1>Hi</h1>
    <?php
    }
    else {
    ?>
    <h1>Please Login</h1>
    <?php
    }
    ?>
    This might seem a bit confusing though for people who are new at PHP.
    Cool, I didn't know you could just break off PHP in the middle of an if statement like that :drool:

+ Reply to Thread

Similar Threads

  1. PHP causing HTTP 500 error?
    By DuBistKomisch in forum Free Hosting
    Replies: 2
    Last Post: 02-07-2009, 07:30 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. Unix Shell Script
    By kbjradmin in forum Programming Help
    Replies: 2
    Last Post: 01-23-2009, 09:59 AM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  5. [PHP] Placing the Ads in PHP Pages
    By Chris in forum Tutorials
    Replies: 22
    Last Post: 06-04-2005, 11:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers