Page 1 of 1

Checking textbox against DB field

Posted: Sat Oct 24, 2009 8:08 am
by nite4000
I am trying to check the input of a textbox against the field of the db. however i am having problems with getting the error msg to show.

Code: Select all

if(strlen($_POST['cancel'])) { //cancel button
 
if($_POST['pin'] != $pin) { //if the text box does not match the dbfield
    $error=TRUE;
    $msg.='<li>You did not enter the security code correctly!</li>'; //show error msg
} else {
$r = mysql_query("delete from Users WHERE pin='".$_POST['pin']."'")or die (mysql_error()); //execute query
 
Now the problem is that i just cant seem to get it to show error if its the wrong pin. and if its the right one it stays on the page which its suppose to redirect. Here is my code for the form


Code: Select all

 <?php 
if($DONE==TRUE) {
?>
                          <h4 class="left_nav" style="margin-top: 1em;">Account Being Deleted..Please Wait... </h4>
              <p>You are now being logged out. Sorry to see you go</p>
              <?php
} else { 
?>
    <?php if($error==TRUE) { echo "<ul><font color=red>$msg</font></ul>"; } ?><form action="termination.php" method="post"><table width="100%">
              <tr>
                <td width="31%">Security Code : </td>
                <td width="69%"><input name="pin" type="text" id="pin" style="width: 200px;" maxlength="20"></td>
              </tr>
               <tr>
                <td colspan="2"><div align="center"><input name="cancel" type="submit" id="cancel" value="Cancel My Account" /></div></td>
              </tr>
              </table>
        </form> <?php } ?> 

I hope someone can help me out i know I must be forgetting something to let it work.


Thanks

Re: Checking textbox against DB field

Posted: Sun Oct 25, 2009 9:02 am
by midohioit
First thing I would do is set your variable to a string:

Code: Select all

 
$error="TRUE";
 
The same with $DONE as well.

Also where are you setting the variable $DONE at? if it is not set that is your first condition and how is it going to enter into your if statement?

You may want to echo out your variables before your if statement to truely see what your dealing with. I would recomend doing an exit(); afterwords so prevent any damange to data..