Web Analytics Made Easy -
StatCounter trouble with tutorial (newbie question) - CodingForum

Announcement

Collapse
No announcement yet.

trouble with tutorial (newbie question)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • trouble with tutorial (newbie question)

    I am a complete & utter newbie to PHP so please bear with me....

    I am going through the tutorial at http://www.technobreeze.com/php/tutorial/index.html

    Everything works until I get down to the "Forms / Regular Expressions" tutorial. All I get is a blank screen. When I view the source code all I see is "<html><body></body></html>" That's it. Can anyone please look at the code and tell me what's wrong? Is it possibly my version of PHP on my server? If it is, I don't know how to figure out what version it is and what version the tutorial needs. I'd like for this tutorial to work because I need something like this for real life.

    Also the MySql tutorial does the same thing and I will be needing to do something like this as well for a real world application.

    Thanks ever so much in advance,
    - sharyn
    'tis best not to get worked up over nothing

  • #2
    Couldn't see anything obvious as I glanced through the code at that site that shoud affect you.

    Can you post the code as you have it on your server and what version of PHP are you running? A good way to find out everything about your configuration of PHP is to create a file and name it something like phpinfo.php and put this and only this in it:

    PHP Code:

    <?php
    phpinfo
    ();
    ?>
    Run the page and it will tell show you everything you need to know.

    Also that tutorial you are reading is a bit out of date so you might want to look for some newer ones to begin learning with. For example that tutorial uses deprecated superglobal variables such as

    $HTTP_POST_VARS and $HTTP_GET_VARS

    those are both replaced with

    $_POST and $_GET

    there are other outdated ones in there too.

    www.phpfreaks.com
    www.zend.com
    www.php.net

    are some good sites to read through for learning PHP.
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      Thanks Spookster.

      Thanks for the newer links. You know how it is when you are a newbie. You don't know where to start.


      I am running PHP version 4.1.2

      The code looks like this :

      PHP Code:

      <?php
      # Copyright (C) 2000 - 2003 Ben Drushell
      # FILE: A_regexp.php

      $TITLE "PHP FORMS / REGULAR EXPRESSIONS";

      function 
      VERIFY_EMAIL($EMAIL)
      # RETURN EMAIL VALIDITY
          
      $valid 0;
          
      $EMAIL chop($EMAIL); # remove white space
          
      $ValidAt strpos($EMAIL,"@"); # check for @
          
      $ValidLen strlen($EMAIL);
          
      $ValidCom strpos(substr($EMAIL,$ValidAt,$ValidLen $ValidAt),".");
          if ((
      $ValidAt 0)&&($ValidAt $ValidLen)&&($ValidCom 0))
          { 
      $valid 1; }
          return(
      $valid);
      }

      function 
      SECURE_FIELD(&$FIELD)
      # PASSING VALUE BY REFERENCE
          
      $FIELD trim($FIELD);
          
      $FIELD ereg_replace("\-+(.*)","\\1",$FIELD);
          
      $FIELD ereg_replace("(.*)[[:space:]]\-(.*)","\\1\\2",$FIELD);
          
      $FIELD ereg_replace("[\$\'\`\"\<\>\/\;\!\|]","_",$FIELD);
      }

      function 
      VERIFY_REQUIRED($RequiredName,$RequiredValue,$myValid,$myErrors)
      {
          
      $return[];
          if (
      strlen($RequiredValue)==0)
          {
              
      $myValid 0;
              
      $myErrors .= "\n<br>Field \"$RequiredName\" requires input.";
          }
          
      $return[0] = $myValid$return[1] = $myErrors;
          return(
      $return);
      }

      function 
      EMAIL_SCREEN($InputEmail,$InputName)
      # Takes input as and saves as input box value
      ?>
          <form action="A_regexp.php" method="post">
          <input type="hidden" name="REQUIRED" value="EMAIL;NAME">
          <br>PLEASE PROVIDE AN
          <br>E-MAIL ADDRESS:<br>
          <input type="text" name="EMAIL" value="<?echo $InputEmail ?>">
          <br>NAME:<br>
          <input type="text" name="NAME" value="<?echo $InputName ?>">
          <br><br><input type="submit" value="VERIFY">
          </form>
      <?php
      }

      $VALID 1;
      $error "";

      if(
      $REQUIRED)
      {
          
      SECURE_FIELD($EMAIL);
          
      SECURE_FIELD($NAME);

          
      $VALID VERIFY_EMAIL($EMAIL);
          if (
      $VALID==0)
          { 
      $error .= "\n<br>Field EMAIL requires valid structure!"; }

          
      $RequiredList split(";",$REQUIRED);
          while (list(
      $FIELD_KEY,$FIELD_VALUE) = each($RequiredList))
          { list(
      $VALID,$error) = VERIFY_REQUIRED(
                  
      $FIELD_VALUE,
                  
      $HTTP_POST_VARS[$FIELD_VALUE],
                  
      $VALID,$error); }

          if(
      $VALID==1)
          { 
      # cookie information must be set in the header of the document
            # this means before the document actually starts sending HTML code
              
      setcookie("EMAILCookie",$EMAIL,time()+180);  # expire in 3 min.
              
      setcookie("NAMECookie",$NAME,time()+180);  # expire in 3 min.
              
      setcookie("IPCookie",$REMOTE_ADDR,time()+180);  # expire in 3 min.
              # The first field specifies the field name for retrieving info later.
              # The second field contains the value to store.
              # The third field is option and contains an time expiration for cookie
          
      }
      }
      ?>

      <HTML>
      <HEAD>
      <TITLE><?php echo $TITLE ?></TITLE>
      </HEAD>
      <BODY>
      <CENTER><BIG><B>
      <?php echo $TITLE# output title ?>
      </B></BIG></CENTER>
      <BR><BR>

      <?php
      if($HTTP_COOKIE_VARS["IPCookie"])
      # system variable array for retrieving cookie information
          
      echo "Welcome " $HTTP_COOKIE_VARS["NAMECookie"]. " <br>";
          echo 
      "You last successfully accessed this file from ";
          echo 
      $HTTP_COOKIE_VARS["IPCookie"];
          echo 
      ".<br><br>";
      }
      if (
      $REQUIRED)
      {
          if(
      $VALID==1)
          { echo 
      "Thank you, $NAME$EMAIL has valid structure.<br><br>"; }
          else
          { echo 
      "THERE WAS AN ERROR!<br> $error"; }
      }
      EMAIL_SCREEN(
          
      $HTTP_COOKIE_VARS["EMAILCookie"],
          
      $HTTP_COOKIE_VARS["NAMECookie"]);
      ?>

      </BODY>
      </HTML>
      Last edited by Spookster; Feb 6, 2004, 07:40 PM.
      'tis best not to get worked up over nothing

      Comment


      • #4
        In the future when posting code you can use the [ php ] [ / php ] tags around the code and it will highlight the code as it is doing now that I edited your post. Makes it easier to read.

        First thing you can do since you are using PHP version >4.1.0 is to change all instances of

        $HTTP_POST_VARS
        $HTTP_GET_VARS
        $HTTP_COOKIE_VARS

        with

        $_POST
        $_GET
        $_COOKIE

        Those are the new superglobals to use. You can read more about them here:

        http://us2.php.net/variables.predefined
        Spookster
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment


        • #5
          The problem code is right here where I have commented it:

          PHP Code:

          function  VERIFY_REQUIRED($RequiredName,$RequiredValue,$myValid,$myErrors)
          {


             
          // Problem code is here
              
          $return[]; 
             
          // ????


              
          if (strlen($RequiredValue)==0)
              {
                  
          $myValid 0;
                  
          $myErrors .= "\n<br>Field \"$RequiredName\" requires input.";
              }
              
          $return[0] = $myValid$return[1] = $myErrors;
              return(
          $return);

          Not sure what the author was trying to do there. It looks like they wanted to declare an array but delcaring an array should be done like so:

          $return = array();

          I don't have time to do anymore debugging right now but that is where the first problem is.
          Last edited by Spookster; Feb 6, 2004, 08:06 PM.
          Spookster
          CodingForum Supreme Overlord
          All Hail Spookster

          Comment


          • #6
            Spookster ! You are a the best !

            The array declaration was EXACTLY what the problem was... and now I'm switching over to one of your other suggested tutorial sites now that I know that this one isn't one of the best..

            Thanks a million !

            - sharyn
            'tis best not to get worked up over nothing

            Comment

            Working...
            X