Jump to content

check if record exists


ukdeveloper

Recommended Posts

I am the newest of new to PHP and am just starting to code my first project.

 

I have a database (db_code) with a single table (tbl_code) with 1000 records of 8 digits. something like DHYHGTYF, SBEYFISN etc.

 

All i wish to do is create a form which a user enters a code that they have been given (one of the 8 digit codes). If it matches go to web page one, if they enter a code with does NOT exist then go to web page 2.

 

I guess a bit like a login form but only uses one field.... a code field.

 

Could anyone help me with some syntax?

 

UKD.

Link to comment
Share on other sites

You will need a simple HTML form:

<form method="POST" action="handler.php">
    <input type="text" name="key"/>
    <input type="submit"/>
</form>

Then, in the PHP file (handler.php in this case):

<?php
//mysql_connect()
//mysql_select_db()
$r = mysql_query('SELECT * FROM tbl_code WHERE key = "'.$_POST['key'].'"');
if (mysql_num_rows($r))
    header('Location: success.html');
else
    header('Location: denied.html');
?>

This is very basic, it should work in perfect  circumstances. Don't forget to add error handling and input cleaning.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.