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
https://forums.phpfreaks.com/topic/280771-check-if-record-exists/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.