Help with login/register system and validation
I am trying to create a create a login system but it odes not work or validate. Here is my code:
require_once('dbc.php'); if(isset($_POST['doRegister']) == 'Register') { $required = array('full_name','user_email','pwd','user_name'); $missing = array(); foreach($_POST as $key => $value) { $data[$key] = filter($value); if (empty($value) && in_array($key, $required)) { array_push($missing, $key); } } } if (!empty($missing)) { if($_POST['user_email'] !='') { if (!isEmail($_POST['usr_email'])) { array_push($missing, 'email_invalid'); } } if (!empty($missing)) { if(in_array('full_name', $missing)) { $full_name = 'Please provide your full name'; } } if (!empty($missing)) { if(in_array('user_email', $missing) || in_array('email_invalid', $missing)) { $user_email = 'Please provide your valid email address'; } } if (!empty($missing)) { if(in_array('duplicate', $missing)) { $user_email = 'Email address already registered'; } if (!empty($missing)) { if(in_array('user_name', $missing)) { $user_name = 'Please create a password'; } if (!empty($missing)) { if(in_array('pwd', $missing)) { $pwd = 'Please create a password'; } } else { $sql = "INSERT into `users` (`full_name`,`user_email`,`pwd`,``user_name`) VALUES ('$data[full_name]','$usr_email','$sha1pass','$user_name')"; $success ='<p>Thank you.<br />You have succesfully registered.</p>'; } } } } ?> <html> <head> <title>PHP Login :: Free Registration/Signup Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <?php if (isset($success)) { echo $success; } else { ?> <form action="" method="post" name="regform" id="regform"> <table border="0" cellspacing="0" cellpadding="0"> <?php if (isset($full_name)) { ?> <tr> <th> </th> <td class="warn"><?php echo $full_name; ?></td> </tr> <?php } ?> <tr> <th scope="row"><label for="full_name">Full name</label></th> <td><input type="text" name="full_name2" id="full_name"></td> </tr> <?php if (isset($user_name)) { ?> <tr> <th> </th> <td class="warn"><?php echo $user_name; ?></td> </tr> <?php } ?> <tr> <th scope="row"><label for="user_name">User Name:</label></th> <td> <input type="text" name="user_name2" id="user_name"></td> </tr> <?php if (isset($user_email)) { ?> <tr> <th> </th> <td class="warn"><?php echo $user_email; ?></td> </tr> <?php } ?> <tr> <tr> <th scope="row"><label for="user_email">User Email:</label></th> <td> <input type="text" name="user_email" id="user_email"></td> </tr> <?php if (isset($pwd)) { ?> <tr> <th> </th> <td class="warn"><?php echo $pwd; ?></td> </tr> <?php } ?> <tr> <th scope="row"><label for="pwd">Password</label></th> <td><input type="text" name="pwd3" id="pwd"></td> </tr> <tr> <th scope="row"> </th> <td><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <?php } ?> </body> </html>My database structure is: CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `full_name` tinytext COLLATE latin1_general_ci NOT NULL, `user_name` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '', `user_email` varchar(220) COLLATE latin1_general_ci NOT NULL DEFAULT '', `pwd` varchar(220) COLLATE latin1_general_ci NOT NULL DEFAULT '', PRIMARY KEY (`id`), UNIQUE KEY `user_email` (`user_email`), FULLTEXT KEY `idx_search` (`full_name`,`user_email`,`user_name`) ) ENGINE=MyISAM ;
2 Answers
there is some errors in the code please try this
PHP if($_POST) { $required = array(\'full_name\',\'user_email\',\'pwd\',\'user_name\'); $missing = $data = array(); foreach($_POST as $key => $value) { $data[$key] = filter($value); if (empty($value) && in_array($key, $required)) { array_push($missing, $key); } } if (!empty($missing)) { if($_POST[\'user_email\'] !=\'\') { if (!isEmail($_POST[\'usr_email\'])) { array_push($missing, \'email_invalid\'); } } if(in_array(\'full_name\', $missing)) { $full_name = \'Please provide your full name\'; } if(in_array(\'user_email\', $missing) || in_array(\'email_invalid\', $missing)) { $user_email = \'Please provide your valid email address\'; } if(in_array(\'duplicate\', $missing)) { $user_email = \'Email address already registered\'; } if(in_array(\'user_name\', $missing)) { $user_name = \'Please create a password\'; } if(in_array(\'pwd\', $missing)) { $pwd = \'Please create a password\'; } }else { mysql_query(\"INSERT into `users` (`full_name`,`user_email`,`pwd`,``user_name`) VALUES (\'$data[full_name]\',\'$data[user_email]\',\'$data[pwd]\',\'$data[user_name]\')\"); $success =\'<p>Thank you.<br />You have succesfully registered.</p>\'; } }HTML <html> <head> <title>PHP Login :: Free Registration/Signup Form</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> <link href=\"styles.css\" rel=\"stylesheet\" type=\"text/css\"> </head> <body> <?php if (isset($success)) { echo $success; } else { ?> <form action=\"\" method=\"post\" name=\"regform\" id=\"regform\"> <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <?php if (isset($full_name)) { ?> <tr> <th> </th> <td class=\"warn\"><?php echo $full_name; ?></td> </tr> <?php } ?> <tr> <th scope=\"row\"><label for=\"full_name\">Full name</label></th> <td><input type=\"text\" name=\"full_name\" id=\"full_name\"></td> </tr> <?php if (isset($user_name)) { ?> <tr> <th> </th> <td class=\"warn\"><?php echo $user_name; ?></td> </tr> <?php } ?> <tr> <th scope=\"row\"><label for=\"user_name\">User Name:</label></th> <td> <input type=\"text\" name=\"user_name\" id=\"user_name\"></td> </tr> <?php if (isset($user_email)) { ?> <tr> <th> </th> <td class=\"warn\"><?php echo $user_email; ?></td> </tr> <?php } ?> <tr> <tr> <th scope=\"row\"><label for=\"user_email\">User Email:</label></th> <td> <input type=\"text\" name=\"user_email\" id=\"user_email\"></td> </tr> <?php if (isset($pwd)) { ?> <tr> <th> </th> <td class=\"warn\"><?php echo $pwd; ?></td> </tr> <?php } ?> <tr> <th scope=\"row\"><label for=\"pwd\">Password</label></th> <td><input type=\"text\" name=\"pwd\" id=\"pwd\"></td> </tr> <tr> <th scope=\"row\"> </th> <td><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\"></td> </tr> </table> </form> <?php } ?> </body> </html> Posted: MacOS 1 of 1 people found this answer helpful. Did you? Yes No This code works and validated fields but does not add the details to the database also how could I confirm if the passwords are the same?
lol, i'm sorry there is no mysql_query to execute it
what about this:Php User Clas
Posted: greentree 2 of 2 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved