Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: ECHO does not work in php

  1. #1
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default ECHO does not work in php

    Edited: I found out that I cannot echo at all. I tried a small program below and when I run it, I get a blank page.
    PHP Code:
    <html>
    <body>
    <?php 
    echo 'You will be re-directed in 3 seconds';
    ?>
    </body>
    </html>
    The original problem is below:

    I have a piece of code below and when I get to this condition, I want to print "You have already registered" and then return to the page shown in the "header" line

    Before the following php code, I have checked mysql and either found 1 or 0 records. If I find 1 record, that is when I want to alert the user he is already registered. Thanks for any help

    PHP Code:
    if ($num==1) {
      
    mysql_close();
      echo 
    ' you are already registered' ;
      
    header("Location: http://www.lotatennis.com");

    Last edited by mcolton; 03-11-2011 at 03:26 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Are any functions working for you?

    Try doing:

    PHP Code:
    <?php
    phpinfo
    ();
    ?>
    That should print out a lot of information about PHP and your setup.

    If it doesn't, then there's probably something wrong with how your server is set up.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Also no output can be displayed if you are using a header.


    PHP Code:
    echo ' you are already registered' ;
    header("Location: http://www.lotatennis.com"); // this wont execute with the echo 
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    phpinfo didn't show anything.
    I took the "header" line out and still nothing.
    I know I'm getting to this test file because I put a line of text in there:

    PHP Code:
    <html>
    <body>
    text
    <?php 
    phpinfo
    ();
    ?>
    </body>
    </html>
    When I ran this, I got "text" and thats all. If I take the "text" out, I get nothing. I KNOW PHP is working because the whole rest of my code IS working.

  5. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Is the file that this code is in a php file? ie - does it end with the .php extension
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  6. #6
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    no. it is a html file

  7. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    There's your answer
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  8. #8
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I don't understand. That little test file is html. My original code that is not working (below) is in a php file:

    PHP Code:
    if ($num==1) { 
      
    mysql_close(); 
      echo 
    ' you are already registered' 
      
    header("Location: http://www.lotatennis.com"); 


  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Beverley is saying that PHP will only execute when the extension is .php, and never on an .htm or .html page.

    (Technically you could reconfigure your server, but that's not relevant here.)

    For EVERY page on which you are trying to run PHP, is the extension .php? That's step 1. Then try the phpinfo() code again.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Bluewalrus mentioned it, but you may have missed it;

    this won't work:
    Quote Originally Posted by mcolton View Post
    PHP Code:
      echo ' you are already registered' 
      
    header("Location: http://www.lotatennis.com"); 
    the header will fail because you've already sent output (the text) to the browser.
    if you switch the order:
    PHP Code:
      header("Location: http://www.lotatennis.com");
    echo 
    ' you are already registered' 
    then the echo won't be seen, because the user has already been redirected to the other page.

    If you want to do this (show a notice and then redirect), it has to be done on the client side; there's no way to do it from the server. use javascript or a html header.

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
  •