Checking textbox against DB field

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
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Checking textbox against DB field

Post 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
Last edited by califdon on Sat Oct 24, 2009 12:21 pm, edited 1 time in total.
Reason: Replaced code=text with code=php to highlight syntax.
midohioit
Forum Newbie
Posts: 18
Joined: Tue Dec 05, 2006 10:19 am

Re: Checking textbox against DB field

Post 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..
Post Reply