on my tagboard alot of people think its funny to post blank messages..
i figured out how to prevent them from making blank messages, but i can't figure out how to stop them from posting messages with only " " spaces..
i want to make it so if the name is less than three characters it wont post, same with the message
what are the wild cards to do this?
if($var <= "whatgoeshere"){
very simple question
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
The strlen() function can find out the Strings Length, so something like so should work:
Code: Select all
if (strlen($var) < 3) { // Post error message or something }You might want to make it check for spaces as well as for string length. To do that, here's an example:
This code simply tests the length of the string when there aren't any spaces. You could use trim() or chop() or something of the like, but then someone could just type "x x" and easily bypass the validation. The above method actually works pretty well.
Cheers
Code: Select all
if (strlen(str_replace(" ","",$var)) < 3) {
// Post error message or something
}Cheers
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
what about this easy solution
Hi Guys,
Why we don't use
If $var is posted, then execute queries or display outputs, else just type an error messages or redirect another file 
I think it will work too, am i right?
Why we don't use
Code: Select all
if($var){
echo "Text Here";
}
else{
echo "Fill all fields";
}I think it will work too, am i right?