ukdeveloper Posted August 2, 2013 Share Posted August 2, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280771-check-if-record-exists/ Share on other sites More sharing options...
lemmin Posted August 2, 2013 Share Posted August 2, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280771-check-if-record-exists/#findComment-1443219 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.