Forms not working

akhx10mx

New Member
Messages
3
Reaction score
0
Points
0
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:
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
 

akhx10mx

New Member
Messages
3
Reaction score
0
Points
0
Hey, for some reason that code did not post right. Let me try again.

PHP:
<?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="http://x10hosting.com/forums/images/akhlogo2.png"></div>
<div class="header"><img src="http://x10hosting.com/forums/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>
 
Last edited by a moderator:

Skizzerz

Contributors
Staff member
Contributors
Messages
2,929
Reaction score
118
Points
63
Moved to Scripts, 3rd Party Apps, and Programming.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
I suppose I could ask why you aren't using a simple submit-type input for your form submission. A better question, though, would be what browser you might have been using to have this ever work. If it was working at any point, it's been edited to be broken since then.

The problem is these two little items:

PHP:
<form class="registerform" method="post" action="register?submit">
.
.
.
<a href="register?submit" class="source" onclick="document.getElementById('registerform').submit();">

You may notice that the form element doesn't have an id. That means that document.getElementById('registerform') is null and doesn't have a submit() method. But even though the onclick event errors, the link has a valid URL pointing to the same page with a ?submit query. Since you're asking for $_REQUEST["submit"], it doesn't matter whether it's a POST or a GET value, so your script runs even though no form was submitted.

If you absolutely have to use a link, then the URL (the href) should be "#". Nothing more, nothing less. It would be better for everybody's sanity, though, if you used:

HTML:
<input id="register_submit" type="submit" name="submit" value="Register">

It will have a button appearance by default, but you can style it differently. And that will allow you to remove the query string from the form's action as well, since $_REQUEST["submit"] (and $_POST["submit"]) will be set.
 
Last edited:

akhx10mx

New Member
Messages
3
Reaction score
0
Points
0
Oh, wow. I feel pretty stupid right now haha. Thanks so much for the help. With the way I have it set up, I think it needs to stay a link, but I'll definitely make those other changes. I can't believe I didn't notice that haha. Anyway, thanks again for the help.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
You just need a better rubber ducky :)
 
Top