diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2008-02-03 23:23:24 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2008-02-03 23:23:24 +0000 |
| commit | d895b852a6e160496ffc760d46d3719a3d62ff86 (patch) | |
| tree | 52230bb04148197e8312e09b5c5273417e7a3be9 /add_user.php | |
Initial checkin of nutridb.org and basic subversion directory structure
Diffstat (limited to 'add_user.php')
| -rw-r--r-- | add_user.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/add_user.php b/add_user.php new file mode 100644 index 0000000..754c946 --- /dev/null +++ b/add_user.php @@ -0,0 +1,53 @@ +<?php + +include "include/db.php"; + +# make sure that none of the fields are empty +if ($_POST['login']) { + foreach ($_POST as $data) { + if ($data == "") { + $err = "<span class='errors'>You must fill in all fields!</span><br />\n"; + $reg_status == "failed"; + return; + } + } +} + +# make sure that the passwords match +if ($_POST['passwd'] != $_POST['passwd2']) { + $err = "<span class='errors'>Your passwords do not match. Please try again.</span><br />\n"; + $reg_status == "failed"; + return; +} + +# make sure that age is >0 && <100 +if ($_POST['age'] < 1 || $_POST['age'] > 100) { + $err = "<span class='errors'>Your age must be between 1 and 100 (years).</span><br />\n"; + $reg_status == "failed"; + return; +} + +$lnk = db_connect(); + +# make sure that the login does not already exist +$res = db_query("SELECT id_users FROM users WHERE login = '{$_POST['login']}'"); +if (db_num_rows($res)) { + $err = "<span class='errors'>Login name '{$_POST['login']}' is already in use. Please select another.</span><br />\n"; + $reg_status == "failed"; + return; +} + +$hashpwd = md5($_POST['passwd']); + +$qry = " + INSERT INTO users (login, passwd, age, gender) + VALUES ('{$_POST['login']}','$hashpwd', '{$_POST['age']}', '{$_POST['gender']}') +"; + +db_query($qry); + +$reg_status = "ok_passed"; + +db_close($lnk); + +?> |
