Jump to content

[SOLVED] string length problem


merylvingien

Recommended Posts

I know, i am boring you all now  :(

 

I have tried searching for this answer but i cant find the solution.

 

There is something wrong with this code and i cant figure it out!

 

if (strlen($adverttext) < 200) {$advertstrength = "4";}
 else
 if((strlen($adverttext) >= 200) && (strlen($adverttext) < 400)) {$advertstrength = "3";} 
 else
 if ((strlen($adverttext) >= 400) && (strlen($adverttext) < 600)) {$advertstrength = "2";}
 else
 if (strlen($adverttext) >= 600) {$advertstrength = "1";}
 else

Link to comment
Share on other sites

Well without that piece of code in there the page works fine, if i add that code then the page outputs nothing, not even an error.

 

if (strlen($adverttext) < 100) {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($adverttext) > 1000){echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($phone) <  {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($phone) > 16) {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($mobile) > 16) {echo 'error'; include("foot.html"); exit;}
 else
 if ($email == $row['email'] && md5($password) == $row['password']){ continue

that works

 

if (strlen($adverttext) < 100) {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($adverttext) > 1000){echo 'error'; include("foot.html"); exit;}
 else
    if (strlen($adverttext) < 200) {$advertstrength = "4";}
 else
 if((strlen($adverttext) >= 200) && (strlen($adverttext) < 400)) {$advertstrength = "3";} 
 else
 if ((strlen($adverttext) >= 400) && (strlen($adverttext) < 600)) {$advertstrength = "2";}
 else
 if (strlen($adverttext) >= 600) {$advertstrength = "1";}
 else
 if (strlen($phone) <  {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($phone) > 16) {echo 'error'; include("foot.html"); exit;}
 else
 if (strlen($mobile) > 16) {echo 'error'; include("foot.html"); exit;}
 else
 if ($email == $row['email'] && md5($password) == $row['password']){ continue

that doesnt work!

Link to comment
Share on other sites

Without seeing more code, and a better description of what your problem is, and what you expect to happen, we can't really help you. THose if statements look OK, besides the fact that they are strangely formatted, and hard to tell if they are elseifs or else statements with a nested if inside of them

Link to comment
Share on other sites

Well there is no error, the page just outputs nothing and wont update the database.

 

What i am trying to achieve, is if someone enters less than 200 characters in their text, then in the control panel, it will flag up saying that their text is too short and is weak. they should consider updating it.

 

Same sort of thing if the text is between 200 & 400 but its not so bad.

if the text is between 400 & 600 then its quite good.

if its above 600 then its exellent.

Link to comment
Share on other sites

first of all the formatting is really weird I had to really concentrate to have the heart to edit it :P, anyways this should work

 

 

<?php

    if (strlen($adverttext) < 100) {echo 'error'; include("foot.html"); exit;}
    else if (strlen($adverttext) > 1000){echo 'error'; include("foot.html"); exit;}
    else if (strlen($adverttext) < 200) {$advertstrength = "4";}
    else if((strlen($adverttext) >= 200) && (strlen($adverttext) < 400)) {$advertstrength = "3";}
    else if ((strlen($adverttext) >= 400) && (strlen($adverttext) < 600)) {$advertstrength = "2";}
    else if (strlen($adverttext) >= 600) {$advertstrength = "1";}
    
    
    if (strlen($phone) <  {echo 'error'; include("foot.html"); exit;}
    else if (strlen($phone) > 16) {echo 'error'; include("foot.html"); exit;}

    if (strlen($mobile) > 16) {echo 'error'; include("foot.html"); exit;}
    
    if ($email == $row['email'] && md5($password) == $row['password']){ }

?>

 

 

Link to comment
Share on other sites

I would suggest putting the else and the if on the same line. I suspect that php is reading the structure of your if statements incorrectly (or rather, not in the way you intended) is there any more code than this? if so please post it

 

edit: yeah pretty much what raj wrote

Link to comment
Share on other sites

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.