Jump to content

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.");

}

      }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.