SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Malaysia
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What does this mean?

    Dear all,

    I am sorry but I am haveing problems again...

    What does the error message
    Parse error: parse error, unexpected $ in /home/freak/public_html/email_signup_form.php on line 125
    (line 125 is my last line) supposed to mean? Where should I start looking for errors?

    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look whether you have a $ infront of a function.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Malaysia
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've checked, no...

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you post part of your code?

  5. #5
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Malaysia
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I am sorry that my code is messy. But I suppose that is expected of a newbie.

    This is a script that is suppose to let users create email accounts with cpanel.

    PHP Code:
    <? 
      
    include_once "functions.php";
      
    mysql_dbconnect('freak_freak''life@hugo''site');
      
    $quota="5";
      if (
    $submit)
      { 
          
    $ok TRUE;
        if (
    $email="")
        {
            
    $ok=FALSE;
            
    $error_message.="No username entered. ";
        }
        if (
    ereg('-'$email))
        {
            
    $ok=FALSE;
            
    $error_message.="Username cannot contain '-'. ";
        }
        
    //if (ereg(' ', $email))
        //{
            //$ok=FALSE;
            //$error_message.="Username cannot contain spaces. ";
        //}
        //if (ereg('@', $email) or ereg('#', $email) or ereg('$', $email) or ereg('%',$email) or ereg('^',$email) or ereg('&', $email) or ereg('*', $email) or ereg('(', $email) or ereg(')',$email)ereg('+', $email) or ereg('=', $email) or ereg('~', $email) or ereg('`',$email) ereg('!', $email) or ereg('?', $email) or ereg('.', $email) or ereg(',',$email))
        //{
            //$ok=FALSE;
            //$error_message.="Username cannot contain special characters. ";
        //}
        
    $sql="select student_id ,username from email";
        
    $results=mysql_query($sql) or die(mysql_error());
        while (
    $rowmysql_fetch_assoc($results))
        {
            
    $name=$row['username'];
            
    $id=$row['student_id'];
            if (
    $name==$username)
            {
                
    $ok=FALSE;
                
    $error_message.="The username has already been used. ";
            }
            if (
    $id == $_COOKIE['student_id'])
            {
                
    $ok=FALSE;
                
    $error_message="You already have an account!";
            }
        }
        if (
    $ok==FALSE)
        {
            echo
    "There was an error with yoru submission: ";
            echo 
    $error_message;
        } 
        else 
        {    
            
    $time=mytime();
            
    $sql="insert into email values '', '$email', '$password','$time', '$quota'";
            
    $results=mysql_query($sql) or die(mysql_error());
              
    $host "science3.net"
              
    $port 2082
              
    $path "/frontend/rvblue/mail/doaddpop.html"//or .dll, etc. for authnet, etc. 
           
              // these lines are changed 
              
    $cpaneluser "freak"
              
    $cpanelpass "life@hugo"
              
    $authstr "$cpaneluser:$cpanelpass";
              
    //**************************** 
       
              // Setup the Auth String 
              
    $pass base64_encode($authstr); 
           
              
    //Setup an array of all the POST data 
              
    $formdata = array ( "email" => $email"domain" => $host"password" => $password"quota" => $quota); 
              
    //build the post string 
            
    foreach($formdata AS $key => $val)
            { 
                 
    $poststring .= urlencode($key) . "=" urlencode($val) . "&"
            } 
              
    // strip off trailing ampersand 
              
    $poststring substr($poststring0, -1); 
           
              
    $fp fsockopen($host$port$errno$errstr$timeout 30); 
               
              if(!
    $fp)
            { 
                   
    //error tell us 
                   
    echo "$errstr ($errno)\n"
             
              }
            else
            { 
           
                    
    //send the server request 
         
                
    fputs($fp"POST $path HTTP/1.1\r\n"); 
                
    fputs($fp"Host: $host\r\n"); 
                
    fputs($fp"Authorization: Basic $pass \r\n"); 
                
    fputs($fp"Content-type: application/x-www-form-urlencoded\r\n"); 
                
    fputs($fp"Content-length: ".strlen($poststring)."\r\n"); 
                
    fputs($fp"Connection: close\r\n\r\n"); 
                
    fputs($fp$poststring "\r\n\r\n"); 
                   echo 
    "Your email account should have been created. Please <a href\"../email.php\">click here</a> to go back to the e-mail page.<br>";
                  echo 
    "Should there be any problem, please contact me to have it sorted out";
                
    //************************************ 
                
                  // Remove this to stop it from displaying the output fron the CPanel 
                  //************************************* 
                //loop through the response from the server 
                   /* while(!feof($fp)) 
                { 
                     echo fgets($fp, 4096); 
                } 
             
         
                //close fp - we are done with it 
                fclose($fp); 
              }     
              print  "Email Account Created"; 
          }else{ */
    }
      
    ?> 
      <table>
      <form method="post" action="<?php echo $PHP_SELF?>"> 
      <tr><td>Username:</td><td><input type="text" name="email"></td></tr>
      <tr><td>Password:</td><td><input type="password" name="password"></td> </tr>
      <tr><td>Quota:</td><td>5</td></tr> 
      <input type="submit" name="submit" value="true"> 
      </table></form>
      <?php ?>
    Thanks.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok.. the lines i've add are commented with '<<<<<'.. check your code to see that they should be really there.. because i get lost in so many IF statements
    the most important rule with so many IF statements and loops is right indent and tabulation.. that will save you very time for debugging (also editor with matching bracket highlighting)
    PHP Code:
    <?php
      
    include_once "functions.php"
      
    mysql_dbconnect('freak_freak''life@hugo''site'); 
      
    $quota="5"
      if (
    $submit
      { 
          
    $ok TRUE
        if (
    $email=""
        { 
            
    $ok=FALSE
            
    $error_message.="No username entered. "
        } 
        if (
    ereg('-'$email)) 
        { 
            
    $ok=FALSE
            
    $error_message.="Username cannot contain '-'. "
        } 
        
    $sql="select student_id ,username from email"
        
    $results=mysql_query($sql) or die(mysql_error()); 
        while (
    $rowmysql_fetch_assoc($results)) 
        { 
            
    $name=$row['username']; 
            
    $id=$row['student_id']; 
            if (
    $name==$username
            { 
                
    $ok=FALSE
                
    $error_message.="The username has already been used. "
            } 
            if (
    $id == $_COOKIE['student_id']) 
            { 
                
    $ok=FALSE
                
    $error_message="You already have an account!"
            } 
        } 
        if (
    $ok==FALSE
        { 
            echo
    "There was an error with yoru submission: "
            echo 
    $error_message
        } 
        else 
        {     
            
    $time=mytime(); 
            
    $sql="insert into email values '', '$email', '$password','$time', '$quota'"
            
    $results=mysql_query($sql) or die(mysql_error()); 
              
    $host "science3.net"
              
    $port 2082
              
    $path "/frontend/rvblue/mail/doaddpop.html"//or .dll, etc. for authnet, etc. 
              
    $cpaneluser "freak"
              
    $cpanelpass "life@hugo"
              
    $authstr "$cpaneluser:$cpanelpass"
              
    $pass base64_encode($authstr); 
              
    $formdata = array ( "email" => $email"domain" => $host"password" => $password"quota" => $quota); 
            foreach(
    $formdata AS $key => $val
            { 
                 
    $poststring .= urlencode($key) . "=" urlencode($val) . "&"
            } 
              
    // strip off trailing ampersand 
              
    $poststring substr($poststring0, -1); 
            
              
    $fp fsockopen($host$port$errno$errstr$timeout 30); 
               
              if(!
    $fp
            { 
                   
    //error tell us 
                   
    echo "$errstr ($errno)\n"
             
              } 
            else 
            { 
          
                
    fputs($fp"POST $path HTTP/1.1\r\n"); 
                
    fputs($fp"Host: $host\r\n"); 
                
    fputs($fp"Authorization: Basic $pass \r\n"); 
                
    fputs($fp"Content-type: application/x-www-form-urlencoded\r\n"); 
                
    fputs($fp"Content-length: ".strlen($poststring)."\r\n"); 
                
    fputs($fp"Connection: close\r\n\r\n"); 
                
    fputs($fp$poststring "\r\n\r\n"); 
                   echo 
    "Your email account should have been created. Please <a href\"../email.php\">click here</a> to go back to the e-mail page.<br>"
                  echo 
    "Should there be any problem, please contact me to have it sorted out"
                } 
        }             
    // <<<<<
      
    } else {      // <<<<<
      
    ?> 
      <table> 
      <form method="post" action="<?php echo $PHP_SELF?>"> 
      <tr><td>Username:</td><td><input type="text" name="email"></td></tr> 
      <tr><td>Password:</td><td><input type="password" name="password"></td> </tr> 
      <tr><td>Quota:</td><td>5</td></tr> 
      <input type="submit" name="submit" value="true"> 
      </table></form> 
      <?php ?>
    and just a note: your error wasn't "unexpected $", but "unexpected $end", that means that you forgot to close some bracket..

  7. #7
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my experience when you get an error on the last line of your file it is due to, as dacool mentioned, forgetting to close some bracket. Go back through and check all of your if(), else(), while(), and for() logics.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  8. #8
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Malaysia
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    because i get lost in so many IF statements
    so sorry about that...

    Thanks all for helping, I'll go and test it out and will return if it isn't fixed...

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I modified a few parts, mainly performance issues :
    PHP Code:
    <?php
      
    include_once "functions.php";
      
    mysql_dbconnect('freak_freak''life@hugo''site');
      
    $quota="5";
      
        if (
    $submit)
         {
         
          
    /**********************ERROR CHECKING*************************/
          
    $error_message '';
            
          if (
    $email="") {
        
    $error_message.="No username entered. ";
          }
        
        
    //STRPOS is WAY faster than ereg
          
    if (strpos($email'-')) {
              
    $error_message.="Username cannot contain '-'. ";
          }
          
          if (
    strpos($username' ') || strpos($email' ')) {
              
    $error_message.="Username and emails cannot contain spaces. ";
          }
          
              
    //Legal characters check
              
          
    $validmask="abcdefghijklmnopqrstuvwxyz0123456789_";
          
          
    $str=strtolower($username);
          
          if (!
    strspn($str$validmask) == strlen($str)) {
            
    $error_message.="Username cannot contain special characters. "
          }
          
          
    //No need to get ALL usernames !
          
    $student_id=$_COOKIE['student_id'];
          
    $sql="select student_id, username from email WHERE student_id='$student_id' OR username='$username' ";
          
          if( 
    mysql_num_rows(mysql_query($sql)) !==) {
          
    $error_message.="The username has already been used AND/OR you already have an account.  ";
          }
          
    /**********************END ERROR CHECKING*************************/
          
          
          
         //Do cheking direclty on error message variable
         
    if ($error_message!=="")
           {
            echo 
    "There was an error with your submission: ";
            echo 
    $error_message;
        
          } else {     
        
            
    $time=mytime();
            
    $sql="insert into email (//Comment:Where are the fields gone !?) VALUES('', '$email', '$password','$time', '$quota')";
            
    $results=mysql_query($sql) or die(mysql_error());
              
    $host "science3.net";
              
    $port 2082;
              
    $path "/frontend/rvblue/mail/doaddpop.html"//or .dll, etc. for authnet, etc.
              
    $cpaneluser "freak";
              
    $cpanelpass "life@hugo";
              
    $authstr "$cpaneluser:$cpanelpass";
              
    $pass base64_encode($authstr);
              
    $formdata = array ( "email" => $email"domain" => $host"password" => $password"quota" => $quota);
              
                foreach(
    $formdata AS $key => $val)
                 {
                     
    $poststring .= urlencode($key) . "=" urlencode($val) . "&";
                 }
                 
              
    // strip off trailing ampersand
              
    $poststring substr($poststring0, -1);
            
              
    $fp fsockopen($host$port$errno$errstr$timeout 30);
              
              if(!
    $fp) {
                   echo 
    "$errstr ($errno)\n";
             
              } else {
          
                
    fputs($fp"POST $path HTTP/1.1\r\n");
                
    fputs($fp"Host: $host\r\n");
                
    fputs($fp"Authorization: Basic $pass \r\n");
                
    fputs($fp"Content-type: application/x-www-form-urlencoded\r\n");
                
    fputs($fp"Content-length: ".strlen($poststring)."\r\n");
                
    fputs($fp"Connection: close\r\n\r\n");
                
    fputs($fp$poststring "\r\n\r\n");
                   echo 
    "Your email account should have been created. Please <a href\"../email.php\">click here</a> to go back to the e-mail page.<br>";
                   echo 
    "Should there be any problem, please contact me to have it sorted out";
                   
                     }
        } 
      } else {
      
    $PHP_SELF=$_SERVER['PHP_SELF'];
      
      
    //Switching in/out of php for such a small block of text is not a good idea.
      
    echo <<<EOTEXT
      <table>
      <form method="post" action="
    $PHP_SELF">
      <tr><td>Username:</td><td><input type="text" name="email"></td></tr>
      <tr><td>Password:</td><td><input type="password" name="password"></td> </tr>
      <tr><td>Quota:</td><td>5</td></tr>
      <input type="submit" name="submit" value="true">
      </table></form>
      EOTEXT;
      
      ?>

  10. #10
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Malaysia
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow...
    Thanks a bunch louism...

    This code looks so much prettier...

    Thanks, really//


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
  •