How Can I Check This?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasejunk
Forum Newbie
Posts: 6
Joined: Tue Jul 07, 2009 6:24 pm

How Can I Check This?

Post by jasejunk »

How can I check if the text inputted into a form matches the text I want (like a captcha).

Thanks in advance.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: How Can I Check This?

Post by Eric! »

jasejunk
Forum Newbie
Posts: 6
Joined: Tue Jul 07, 2009 6:24 pm

Re: How Can I Check This?

Post by jasejunk »

Basically, this is the code I'd like to use.

Code: Select all

<?php
if $_POST['securityAnswer'] == qrjeyas
    {
        header ('Location: /login.html');
    }
?>
But instead of running the script, it just shows the .php page on the site.

The input for this is

Code: Select all

<input name="securityAnswer" maxlength="12" onKeyUp="javascript&#058; return inputLengthCheck(9);" width="300"></td>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How Can I Check This?

Post by califdon »

Assuming that you are trying to compare what was entered with a string, you have to enclose the string in quotation marks.
jasejunk
Forum Newbie
Posts: 6
Joined: Tue Jul 07, 2009 6:24 pm

Re: How Can I Check This?

Post by jasejunk »

Yeah, I fixed that, but still nothing.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How Can I Check This?

Post by califdon »

jasejunk wrote:

Code: Select all

<?php
if $_POST['securityAnswer'] == qrjeyas
    {
        header ('Location: /login.html');
    }
?>
So if the user enters the correct password, you want to redirect to login.html??
jasejunk
Forum Newbie
Posts: 6
Joined: Tue Jul 07, 2009 6:24 pm

Re: How Can I Check This?

Post by jasejunk »

Yes indeed. But only if they enter that. If not, I want it to go to an error screen.
Thanks for your help btw.
insight
Forum Commoner
Posts: 52
Joined: Tue Jul 07, 2009 9:12 am

Re: How Can I Check This?

Post by insight »

jasejunk wrote:Yes indeed. But only if they enter that. If not, I want it to go to an error screen.
Thanks for your help btw.
On your code shouldn't it be like this instead:

Code: Select all

<input name="securityAnswer" maxlength="12" onKeyUp="javascript&#058; return inputLengthCheck(9);" width="300" /></td>
And not
<input name="securityAnswer" maxlength="12" onKeyUp="javascript&#058; return inputLengthCheck(9);" width="300"></td>
Also wouldn't it work if you had an else statement? For example, if the uses uses the correct password then it will direct them to login.html, otherwise it will direct them to an error page.

Code: Select all

  1. <?php
   2. if $_POST['securityAnswer'] == qrjeyas
   3.     {
   4.         header ('Location: /login.html');
   5.     }
   6. ?>
 
Should be
 
   1. <?php
   2. if $_POST['securityAnswer'] == qrjeyas
   3.     {
   4.         header ('Location: /login.html');
   5.     }
   6. else
   7.     {
   8.         header('Location: /error.html');
   9.     }
   10. ?>
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: How Can I Check This?

Post by SvanteH »

Worth noticing that it will treat qrjeyas as an constant (as someone stated earlier).
Always encase strings with " " or ' '
(hint: insight)

:)
Post Reply