Help: php script ends unexpectedly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
masterjee
Forum Newbie
Posts: 3
Joined: Wed May 05, 2010 2:30 am

Help: php script ends unexpectedly

Post by masterjee »

I am trying to post a form to itself for user infput validation....I start php script with <?php.... the problem is when I use '>' to compare a string lenth using strlen() function to a variable $length, my script ends and remainder of the script is visible on my html web page.......can anyone plz explain why it happens......

Code: Select all

<?php
  
//sanitycheck

function sanityCheck($string, $type, $length){

  // assign the type
  $type = 'is_'.$type;

  if(!$type($string))
    {
    return FALSE;
    }
  // now we see if there is anything in the string
  elseif(empty($string))
    {
    return FALSE;
    }
  // then we check how long the string is
// the > sign in the following line ends php script and the remaining code is visible on html page containing this script
  elseif (strlen($string) > $length)
    {
    return FALSE;
    }
  else
    {
    // if all is well, we return TRUE
    return TRUE;
    }
}

?>
Last edited by masterjee on Thu May 06, 2010 1:35 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help: php script ends unexpectedly

Post by requinix »

You haven't installed PHP properly. Go through the installation instructions again and find out what steps you didn't follow correctly/at all.
masterjee
Forum Newbie
Posts: 3
Joined: Wed May 05, 2010 2:30 am

Re: Help: php script ends unexpectedly

Post by masterjee »

I'm a newbie and don't know much about php.....please help. My .php resides on a web server and I'm testing/running it directly from there....so i think no issue regarding install on my system concerns. All my scripts run well but the problem arises wherever i use 'greater than' logical operator (>)...... this symbol marks the end of php script.......please help!
minorDemocritus
Forum Commoner
Posts: 96
Joined: Thu Apr 01, 2010 7:28 pm
Location: Chicagoland, IL, USA

Re: Help: php script ends unexpectedly

Post by minorDemocritus »

Edit your original post, select all the code, and click the 'PHP Code' button in the editor bar. Syntax highlighting is nice.

tasairis is right, either PHP is not installed correctly, or it's not installed at all. Try viewing the script in your browser via the web address. If it still does the same thing, right click the page and select "View Page Source". I'll bet that you'll see the entire PHP script in the popup.

This is because the webserver is not parsing the script as PHP... it's just sending the text of the script to the browser.

Also, try making a file called phpinfo.php. Use the following code in the script:

Code: Select all

<?php
phpinfo();
?>
Run that script... if it gives you a bunch of information about PHP and the web server, then it's probably installed correctly.
masterjee
Forum Newbie
Posts: 3
Joined: Wed May 05, 2010 2:30 am

Re: Help: php script ends unexpectedly

Post by masterjee »

Thanks for help, minorDemocritus!
I hadn't php installed on my system at the time of first post. I was just writing the script, uploading it to the web host and testing the script in my browser. I rephrase the problem: "All my scripts ran smoothly unless i used a '>' symbol in the script. When i use logical operator '>' anywhere in my code, the remainder of the code was just sent to the browser as just a text."
However, now i've installed php on my system (with IIS on Microsoft Windows XP) and the same scripts run smoothly. Does that mean php is not installed properly on the web hosting company I'm running my script on?
P.S.

Code: Select all

<?php phpinfo(); ?> 
works fine on both my system and web hosting company.
minorDemocritus
Forum Commoner
Posts: 96
Joined: Thu Apr 01, 2010 7:28 pm
Location: Chicagoland, IL, USA

Re: Help: php script ends unexpectedly

Post by minorDemocritus »

It certainly appears that way. Contact the web host's support with those examples, and tell them to fix it!.
Post Reply