Submit button not working... need new eyes?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjfletch
Forum Newbie
Posts: 13
Joined: Mon Apr 18, 2005 5:42 am

Submit button not working... need new eyes?

Post 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'); 
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
jjfletch
Forum Newbie
Posts: 13
Joined: Mon Apr 18, 2005 5:42 am

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 :)
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

try

Code: Select all

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