Hello! I am having a problem with submitting forms on my site. I have a code that I know for a fact works, because both I and a friend have tested it on localhost servers. But when i put it on the website and submit the form, all the fields return blank. The only fields that work are the password fields, but even then only because I have them encrypted in sha1, which encrypts even if it's a blank field. Here is what I have in a registration form:
Every time I submit the form, no matter what I put in the fields, they return blank, and I honestly can not figure out why.
Any help would be much appreciated.
~Alden
Code:
<?php include"config.php"; // PHP CODE TO EXECUTE WHEN FORM IS SUBMITTED // FIRST CHECK THAT THE SUBMIT BUTTON HAS BEEN PRESSED if (isset($_REQUEST['submit'])){ // The line above will return true if the form has been submited // Sanitize variables (trim all whitespace) $n = $_POST['name']; $u = preg_replace('#[^a-z0-9]#i', '', $_POST['username']); $p = sha1($_POST['password']); $cp = sha1($_POST['confirmpass']); $rc = $_POST['code']; // Create variable array to hold errors $e = array(); // Check if anything is blank if ($n == ''){ // Insert into next available place in array $e[] = 'Name is blank'; } if ($u == ''){ // Insert into next available place in array $e[] = 'Username is blank'; } if ($p == ''){ // Insert into next available place in array $e[] = 'Password is blank'; } if ($cp == ''){ // Insert into next available place in array $e[] = 'Confirm is blank'; } if ($rc == ''){ // Insert into next available place in array $e[] = 'Code is blank'; } // Check if username is taken (LONGEST CODE LOL) $sql = 'select username from members where username = "'.$u.'" limit 1'; $query = mysql_query($sql); $rows = mysql_num_rows($query); if ($rows > 0){ // Meaning a username with type user is in database // User exists $e[] = 'Username is taken, please choose another'; } // Check if password >= 6 chars if (strlen($p) < 6){ // INsert error into array $e[] = 'Password must be 6 or more characters'; } // Check if password = c pass if ($p != $cp){ // Insert into next available place in array $e[] = 'Passwords do not match'; } // Check if array is empty (no errors were passed into the array) if (empty($e)){ /* * THIS IS WHERE YOU WILL PUT THAT USER INTO DATABASE * USE MYSQL_REAL_ESCAPE_STRING FIRST ON EACH VARIABLE CREATED * THEN YOU CAN HEADER THEM TO THE LOGIN PAGE */ $n = mysql_real_escape_string($n); $u = mysql_real_escape_string($u); $p = mysql_real_escape_string($p); $insert = 'INSERT into members(name, username, password) VALUES("'.$n.'","'.$u.'","'.$p.'")'; $query = mysql_query($insert); } } ?> <DOCTYPE html> <html> <head> <title>Register for AKH</title> <div class="logo"><img src="images/akhlogo2.png"></div> <div class="header"><img src="images/headerbg.png"></div> </head> <body> <link rel="stylesheet" href="main.css"> <link rel="stylesheet" href="registerpage.css"> <form class="registerform" method="post" action="register?submit"> <div class="loginlink">Already have an account? <a href="login" >Login</a> here.</div> <div class="registrationerrors"><?php if (count($e) > 0){ // Errors do exist echo '<ul>'; $i = 0; while ($i < count($e)){ echo '<li>'.$e[$i].'</li>'; $i++; } echo '</ul>'; } ?></div> <h1>Register...</h1> <table> <tr><td width="150px">Name:</td> <td><input class="say" name="name" type="text" value="Your Name" onClick="value=''"/></td></tr> <tr><td>Username:</td> <td><input class="say" name="username" type="text" value="Your Desired Username" onClick="value=''"/></td></tr> <tr><td>Password:</td> <td><input type="password" name="password" class="say" /></td></tr> <tr><td>Confirm Password:</td> <td><input type="password" name="confirmpass" class="say" /></td></tr> <tr><td>Registration Code:</td> <td><input class="say" name="code" type="text" /></td></tr> <tr><td><a href="#" class="source"></a></td> <td><a href="register?submit" class="source" onclick="document.getElementById('registerform').submit();">Register</a></td></tr> <div class="hiddensubmit2"><input type="submit" tabindex="-1"/></div> </form> <link href='http://fonts.googleapis.com/css?family=Loved+by+the+King' rel='stylesheet' type='text/css'> </body> </html>
Every time I submit the form, no matter what I put in the fields, they return blank, and I honestly can not figure out why.
Any help would be much appreciated.
~Alden