Page 1 of 1
Help: php script ends unexpectedly
Posted: Wed May 05, 2010 2:42 am
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;
}
}
?>
Re: Help: php script ends unexpectedly
Posted: Wed May 05, 2010 3:21 am
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.
Re: Help: php script ends unexpectedly
Posted: Wed May 05, 2010 1:34 pm
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!
Re: Help: php script ends unexpectedly
Posted: Wed May 05, 2010 2:53 pm
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:
Run that script... if it gives you a bunch of information about PHP and the web server, then it's probably installed correctly.
Re: Help: php script ends unexpectedly
Posted: Thu May 06, 2010 1:44 am
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.
works fine on both my system and web hosting company.
Re: Help: php script ends unexpectedly
Posted: Thu May 06, 2010 12:33 pm
by minorDemocritus
It certainly appears that way. Contact the web host's support with those examples, and tell them to fix it!.