Jump to content

Form validation


anevins

Recommended Posts

Hi there,

 

I've got a HTML textarea with the name attribute of 'review' and I've posted this into a variable called $review.

I want to say if the characters are less than 30, please enter more words etc.

 

The problem is, I get the if statement's error even when there are more than 30 characters.

 

Can anyone figure out why I'm getting this?

if ($review < 30){
echo '<p class="red">Review is too short, please enter at least 15 words</p>';
}

Link to comment
https://forums.phpfreaks.com/topic/232513-form-validation/
Share on other sites

Hi again,

I'm trying to do some form validation.

 

I want to say, if the input in the textarea is greater than 30 and less than 255 characters, do some stuff.

But I think something's wrong with my current if statement:

if ((strlen($review) < 255) && strlen(($review) > 30)){
...
}

 

As when I change the if statement to if(!empty($review)){ ... }, the if statement works.

 

Can you see what's wrong with my strlen if statement?

Link to comment
https://forums.phpfreaks.com/topic/232513-form-validation/#findComment-1196008
Share on other sites

You have a second parenthesis after the second strlen ("strlen((") I think you meant to put it after the second strlen ("strlen($review))"). In any case, its rather needless to enclose both strlen's in parenthesis. I would just write it as:

<?php
if (strlen($review) < 255 && strlen($review) > 30) {
//blahblahblahblah
} else {
//blahblahblahblah
}
?>

Link to comment
https://forums.phpfreaks.com/topic/232513-form-validation/#findComment-1196125
Share on other sites

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.