Jump to content

[SOLVED] Am i using trim correctly


DeanWhitehouse

Recommended Posts

I have this

<?php
$name = htmlentities($_POST['dbhost']);
$name = trim($name);
if(strlen($name) == 0)
{
	echo alert("Enter your host address.");
}
?>
<form action="" method="post">
<input type="text" name="dbhost" value="<?php if(isset($_POST['dbhost']))echo $_POST['dbhost']; else{?>Database Host<?php } ?>" onClick="if(this.value == 'Database Host'){this.value='';}else {this.select();}" onBlur="if(this.value=='') this.value='Database Host';" title="Database Host"><br>
<input type="submit" value="Continue" name="stage1" onClick="this.disabled=true">  <input type="reset" value="Reset"><br><input type="submit" value="Test" name="test">
</form>

 

When i just enter a space , it doesnt show an error. ?? why is this

Link to comment
https://forums.phpfreaks.com/topic/121033-solved-am-i-using-trim-correctly/
Share on other sites

You should probably try wrapping the code in a If strlen() function.. I don't think trim can handle a null character.

 

$name = htmlentities($_POST['dbhost']);

      if( $name )

      {

$name = trim($name);

if(strlen($name) == 0)

{

echo alert("Enter your host address.");

}

      }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.