Page 1 of 1

Submit button not working... need new eyes?

Posted: Sun May 01, 2005 1:14 pm
by jjfletch
Hi there,

The submit button in my script isn't working, and I can't figure out why.... Hoping new eyes will help out?

Code: Select all

<?php 
  
require_once ('../../files/config.inc'); 

$page_title = 'Forgot Your Password'; 
include_once ('header.html'); 
include ('registerfunc.php'); 

define("ROOT_DIR","/home/virtual/abcabcabcabc.com/var/www/html/"); 

if (isset($_POST['submit'])) { 

        require_once ('../../files/mysql_connect.php'); 

        if (empty($_POST['username'])) { 
                $u = FALSE; 
                echo '<p><font color="red" size="1">You forgot to enter your username</font></p>'; 

        } else { 

                $u = escape_data($_POST['username']); 

                //Check for the existence of that username 
  
                $query="SELECT UserID, UserEmail FROM users where username='$u'"; 
                $result = @mysql_query ($query); 
                $row = mysql_fetch_array ($result, MYSQL_NUM); 

                if ($row) { 
                        $uid = $row[0]; 
                        $email = $row[1]; 
                } else { 

                        echo '<p><font color="red" size="1">The submitted username does not match those on file!</font></p>'; 
                        $u = FALSE; 
                } 
        } 

        //If everything is OK 
  
        if ($u) { 

                //Create a new random password 
                $p = substr(md5(uniqid(rand(),1)),3,10); 



                //Make the query 
                $query = "UPDATE users SET password=PASSWORD('$p') WHERE user_id=$uid"; 
                $result = @mysql_query ($query);  

                if (mysql_affected_rows() == 1) { 

                        addpasswd(ROOT_DIR.$u."/admin/", $u, $u, $p); 

                        $body = "Your password to log into abcabcabcabc.com has been temporarily changed to '$p'.  Please login using this password and your  
                                username.  At that time you may change your password to something more familiar."; 

                        mail ($email, 'Your temporary password', $body, 'From: admin@abcabcabcabc.com'); 

                        echo '<h3>Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you hav 
e 
                                logged in with this password, you may change it by clicking on the "Change Password" link.</h3>'; 

                        include('footer.html'); 

                        exit(); 

                } else { 

                        $message = '<p><font color="red" size="1">Your password could not be changed due to a system error.</font></p>'; 
                } 

                mysql_close(); 

                } else { 
                echo '<p><font color="red" size="1">Please try again.</font></p>'; 
                } 
} 

?> 
  
<h1>Reset your password</h1> 
<p>Enter your username below and your password will be reset.</p> 
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<fieldset> 
<p><b>User Name:</b> 
<input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"></p> 
</fieldset> 
<div align="center"> 
<input type="submit" name="submit" value="Reset My Password"></div> 
</form> 

<?php 
include ('footer.html'); 
?>

Posted: Sun May 01, 2005 1:26 pm
by Chris Corbyn
Would you mind telling us what isn't working. How do you know it's not working? Do you get any errors or anything?

Posted: Sun May 01, 2005 1:29 pm
by jjfletch
It's not working as in, it does nothing when pressed. No error messages, nothing.

I've tried 3 things so far:

(1) changing 'submit' to 'submit_button'
(2) validating off of a hidden field
(3) validating off the 'username' field

But, none of these worked. The button still does nothing when pressed.

Also, I added this:

Code: Select all

echo "<li />@ line ".__LINE__." of file ".__FILE__.": before checking for isset(POST[submit])"; 
if (isset($_POST['submit'])) { 
    // if we are in here, say something: 
    exit("<li />Successfully inside of form processing @ line ".__LINE__." of file ".__FILE__);
to the beginning of the code, and was able to see both the echo and exit messages... So, I'm totally at a loss now

Posted: Sun May 01, 2005 1:41 pm
by Ambush Commander
First, check and make sure you're getting into the right conditionals. (There's more than just the first conditional that you have to get through) Try having the script echoing something back to you acknowledging that it's reached the inside of each if{} statement that should be executed. Once you find out where the script is deviating of projected fight path, you can start scrutinizing it more carefully (that segment). Check all the variables, make sure they're what they claim to be.

Posted: Sun May 01, 2005 2:53 pm
by ol4pr0
Well supose there is something wrong with your queries you will never know

Code: Select all

$result = @mysql_query ($query); # Urmm @ ?
and use die statements :)

Posted: Sun May 01, 2005 5:09 pm
by anthony88guy
try

Code: Select all

if($_POST){
 echo "Submit button works";
}