Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    Securimage elseif statement

    Hi guys, im trying to work with Securimage and im having a spot of trouble, basically i have the below code:

    PHP Code:
    include_once $_SERVER['DOCUMENT_ROOT'] . '/captcha/securimage.php';

    $securimage = new Securimage();

    if (
    $securimage->check($_POST['captcha_code']) == false) {
      
    // the code was incorrect
      // you should handle the error so that the form processor doesn't continue

      // or you can use the following code if there is no validation or you do not know how
      
    $message"The security code entered was incorrect!";

    }
    else{ 
    i want to change the else{ statement to an elseif, however i have tried the code below and it still doesnt work, does anyknow have any idea how I can get it to work as an elseif:

    PHP Code:
    if ($securimage->check($_POST['captcha_code']) == true) { 
    PHP Code:
    if ($securimage->check($_POST['captcha_code']) != false) { 
    PHP Code:
    if ($securimage->check($_POST['captcha_code']) !== false) { 
    yet with these the post doesnt work at all. if anyone can help that would be great

    cheers.

    Danny
    Last edited by Dan13071992; 01-15-2012 at 02:55 AM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    12k
    12k is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    0
    Thanked 6 Times in 6 Posts
    With a true/false condition, there are only ever a total of two possibilities. So the if/else if will work, but the following conditions will never be applied. For Example

    PHP Code:
    if (true)
    {

    } else if (
    false)
    {

    }
    else {
         
    //never called because top 2 cover all possibilities.

    May I ask why you are wanting it to be an else if? If you can elaborate, I can tell u another way to write the code.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    basically, i want it with that first part ive showed you, but an elseif statement afterwards (if its true) so that it does the rest of my code, which i didnt display as there is alot of it, but after that i need another captcha sent with a different id thats going to be in another elseif statement, as i didnt want to use else again, just elseif, if that makes sense, unless you want me to upload a picture to show you and ill describe it step by step if that will help?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Your other captcha will need to have a different name. You can't resuse the same captcha in the same post. e.g. name="captcha_code" and name="captcha_code2" then you can do something like this
    PHP Code:
    if ($securimage->check($_POST['captcha_code'])) {  
    // do some php stuff
    }
    else if(
    $securimage->check($_POST['captcha_code2']) {
    // do some other php stuff
    }
    else {
    // no captchas entered were correct

    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry yes that is what i ment by saming with a different id, so in your code you just gave me, in the "else" statement, could i do the error message

    Code:
      $message= "The security code entered was incorrect!";
    also i noticed in this code you just posted there is no check eg:

    PHP Code:

    ($securimage->check($_POST['captcha_code']) == false) { 
    will this still work without the false ??
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Well you can but then the question is if the first one is wrong do you even want to check the second one? Using if elseif you won't ever get to the second one. This goes back to what has already been said. There won't be a third option. It is either true or false. If you want to check both then do something like this
    PHP Code:
    <?php
    if ($securimage->check($_POST['captcha_code'])) {  
    // first captcha valid, do some php stuff
    }
    else {
    // first captcha not valid,
    $message "The security code entered was incorrect!";    
    }
    if(
    $securimage->check($_POST['captcha_code2'])) {
    // second captcha valid, do some other php stuff
    }
    else {
    // second captcha not valid
    $message "The second security code entered was incorrect!";
    }  
    ?>
    Of course now though you will only get one $message, not both so you may need to do something like this if you want to capture multiple messages
    PHP Code:
    <?php
    $errors 
    = array();
    if (
    $securimage->check($_POST['captcha_code'])) {  
    // first captcha valid, do some php stuff
    }
    else {
    // first captcha not valid,
    $errors[] = "The security code entered was incorrect!";    
    }
    if(
    $securimage->check($_POST['captcha_code2'])) {
    // second captcha valid, do some other php stuff
    }
    else {
    // second captcha not valid
    $errors[] = "The second security code entered was incorrect!";


    // now where you want the errors to appear you can do this, this will print out all messages
    foreach($errors as $error)
    {
        echo 
    $error.'<br>';
    }
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    hopefully the picture below will help you understand a bit more:



    the first captcha is for the first box, second is for the second box, seperate captcha codes, as i havent changed the id of each captcha in the picture but i will do that now.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You won't have to if they are two different forms. Are they two different forms? If they are no need to change the names but again you will never hit the "else". You would just use
    PHP Code:
    if ($securimage->check($_POST['captcha_code'])) {  
    // captcha valid, do some php stuff
    }
    else {
    // captcha not valid,
    $message "Incorrect code!";

    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    yes they are two different forms, so using what you just gave me should work, even if i leave both id's as:

    Code:
    captcha_code
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yes that is correct. The latest I gave you should work. No need to do an if/elseif/else, just if/else
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Dan13071992 (01-14-2012)

  • #11
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Yes that is correct. The latest I gave you should work. No need to do an if/elseif/else, just if/else

    yes that worked thanks alot ill be sure to add a thanks to your rep
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #12
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry to bring this back up, but theres one more problem i have, the first captcha part works, if its true then it will work, however im trying to impliment my code into the falst bit in the else:

    PHP Code:
    else {
    // first captcha not valid,
    $vercode = ($_POST['captcha_code']);
    mysql_query("INSERT INTO `vercodes` ( `id` , `username` , `code` , `date` , `passed`) VALUES ('', '$fetch->username', '$vercode', '$date', 'no');") or die (mysql_error());

    $message "The security code entered was incorrect!";    

    however by doing this, its adding it to the database with a blank $_post assoon as someone goes to the page, even without them clicking a post/submit button :S any ideas as to why, or how i can stop this and to only add to the database when the code entered is wrong?
    Last edited by Dan13071992; 01-15-2012 at 02:06 AM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #13
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where is the opening bracket for the else? I'm surprised you aren't getting errors
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #14
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry that was my fault, slight accidental key press after i had copied it over, but whats happening is, on page load, it inserts into the database everything except the vercode, as no vercode has been $_POST as the page has just loaded. whereas its only ment to insert into the DB if the code entered is wrong
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #15
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need to post the rest of your code
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •