SQL & PHP Validation

wolf788

Member
Jan 12, 2011
99
2
I just have a quick question:

If I create a form that checks the database in table 'betab' to see if the inputted code is in the table that if true, it proceeds with the form, however, if false, it wont allow the user to proceed.
 

Khalil

IDK
Dec 6, 2011
1,642
786
I would presume you already have a form with the key input, right? If yes then:

PHP:
if(mysql_num_rows(mysql_query("SELECT `key` FROM `betab` WHERE `key` = '".$_POST["key"]."'")) > 0) {
// continue the form or w/e
} else { // error message here }

If you don't have a form then do something like this:
HTML:
<form method="POST">
<input type="text" name="key" placeholder="The key here!" maxlength="5" /> <!-- add this line if you don't already have it, and if you do have it then change to the name to "key"! -->
</form>


If you don't have a column in your table called "key" then run this sql code:

Code:
ALTER TABLE `betab`
ADD COLUMN `key` VARCHAR(5) NOT NULL;
Change the number between the varchar brackets to what ever the length of the key is!

Now, was that so hard?
 

Users who are viewing this thread

Top