AV Posted February 27, 2008 Share Posted February 27, 2008 Hi everybody, I got script alike this: <?php include('../config.php'); include('../functions.php'); session_start(); db(); ?> <?php include('../templates/header.html'); ?> <?php if(isset($_SESSION['correct'])) { echo '<div id="done">User logged as: '.$_SESSION['correct'].'</div>'; ?> <div id="menu"> <img src="../templates/images/menu.png" alt="Menu" /> <ul> <li><a href="index.php">Home</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> <div id="about"> <img src="../templates/images/manage_users.png" alt="Manage users" /> <div id="text_about"; <form method="post" action="index.php"> <table> <tr><td>New password:</td> <td><input type="text" name="new" class="login"></td></tr> <tr><td>Confirm password:</td> <td><input type="password" name="new2" class="login"></td></tr> <tr><td colspan="2" align="center"> <input type="submit" name="submit" value="Change" class="login_button"></td></tr> </table></form> <?php if(isset($_POST['submit'])) { $new = $_POST['new']; $new2 = $_POST['new2']; if($new == $new2 && !$new2=''){ $new_pass = sha1($new2); $login = $_SESSION['correct']; $result = mysql_query("UPDATE users SET pass='$new_pass' WHERE login='$login'") or die(mysql_error()); if(!$result){ echo 'Changing password phailed'; }else{ echo 'Done!'; } }else{ echo '<br />Passwords dont match!'; } } ?> </div> </div> <?php } else { echo '<div id="warning">*beep* Access denied!<br /><br />'; echo '<a href="login.php">LOG IN</a></div>'; } ?> <?php include('../templates/footer.html'); ?> The problem is that the submit button doesn't work after clicking it. Any ideas what is wrong? Quote Link to comment Share on other sites More sharing options...
tgavin Posted February 27, 2008 Share Posted February 27, 2008 Have you tried stripping out the includes, and other items, getting to the bare essentials? Once you know it's working from there, start adding things back until it doesn't work. Also, did you try print_r($_POST); to see if anything was being posted? Quote Link to comment Share on other sites More sharing options...
poirot Posted February 27, 2008 Share Posted February 27, 2008 Does it post at all? Meaning, does it redirect to the targeted page (index.php) after the click? If it doesn't, you might want to check your HTML. Quote Link to comment Share on other sites More sharing options...
GameYin Posted February 27, 2008 Share Posted February 27, 2008 His HTML is fine. Nothing is wrong with it that I can see. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 not your form m8.... <?php if($_POST['submit']){ $new=$_POST['new']; $new2=$_POST['new2']; if($new==$new2){ echo correct; }else{ echo incorrect; } } ?> <form method="POST" action=" "> <table> <tr><td>New password:</td> <td><input type="text" name="new" class="login"></td></tr> <tr><td>Confirm password:</td> <td><input type="password" name="new2" class="login"></td></tr> <tr><td colspan="2" align="center"> <input type="submit" name="submit" value="Change" class="login_button"></td></tr> </table></form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 get rid off this part then try like my example... && (!$new2='')) <?php if($_POST['submit']){ $new=$_POST['new']; $new2=$_POST['new2']; if(empty($new) || (empty($new2))){ echo "Sorry fill in all the dam form! <br>"; } if( ($new==$new2)){ echo correct; }else{ echo incorrect; } } ?> <form method="POST" action=" "> <table> <tr><td>New password:</td> <td><input type="text" name="new" class="login"></td></tr> <tr><td>Confirm password:</td> <td><input type="password" name="new2" class="login"></td></tr> <tr><td colspan="2" align="center"> <input type="submit" name="submit" value="Change" class="login_button"></td></tr> </table></form> as soon as you do this it will work! <?php include('../templates/header.html'); ?> <?php if(isset($_SESSION['correct'])) { echo '<div id="done">User logged as: '.$_SESSION['correct'].'</div>'; ?> <div id="menu"> <img src="../templates/images/menu.png" alt="Menu" /> <ul> <li><a href="index.php">Home</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> <div id="about"> <img src="../templates/images/manage_users.png" alt="Manage users" /> <div id="text_about"; <form method="post" action="index.php"> <table> <tr><td>New password:</td> <td><input type="text" name="new" class="login"></td></tr> <tr><td>Confirm password:</td> <td><input type="password" name="new2" class="login"></td></tr> <tr><td colspan="2" align="center"> <input type="submit" name="submit" value="Change" class="login_button"></td></tr> </table></form> <?php if(isset($_POST['submit'])) { $new = $_POST['new']; $new2 = $_POST['new2']; if($new == $new2){ $new_pass = sha1($new2); $login = $_SESSION['correct']; $result = mysql_query("UPDATE users SET pass='$new_pass' WHERE login='$login'") or die(mysql_error()); if(!$result){ echo 'Changing password phailed'; }else{ echo 'Done!'; } }else{ echo '<br />Passwords dont match!'; } } ?> </div> </div> <?php } else { echo '<div id="warning">*beep* Access denied!<br /><br />'; echo '<a href="login.php">LOG IN</a></div>'; } ?> <?php include('../templates/footer.html'); ?> Quote Link to comment Share on other sites More sharing options...
AV Posted March 1, 2008 Author Share Posted March 1, 2008 redarrow, it still doesn't work I tried as tgavin said, adding print_r($_POST) to the script but nothing happens. I forgot to say that the whole code I posted here it is index.php Any ideas?? Quote Link to comment Share on other sites More sharing options...
tgavin Posted March 1, 2008 Share Posted March 1, 2008 did you try removing everything php related and testing? If it works, then start adding in the code until it breaks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 1, 2008 Share Posted March 1, 2008 redarrow, it still doesn't work Define what "doesn't work" means. Define what you mean by "the submit button doesn't work after clicking it". neither of those is much help. Something must happen. Presumably it isn't what you expect or hoped for, but what does happen? I suspect your logic is flawed. Quote Link to comment Share on other sites More sharing options...
AV Posted March 2, 2008 Author Share Posted March 2, 2008 Is this really hard to understand that after I click the button nothing happen! Nothing change!! tgavin, I tried removing all the code, it behaves same as before Quote Link to comment Share on other sites More sharing options...
tgavin Posted March 2, 2008 Share Posted March 2, 2008 Is this really hard to understand that after I click the button nothing happen! Nothing change!! Yeah, it is hard to understand, because a submit button should submit. a few questions. 1. Are you trying this on a live web server, or on your PC? 2. Is the name of the file actually index.php? 3. Is there a live example? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 2, 2008 Share Posted March 2, 2008 In you code you have an html error, The following tag is ended wrong: <div id="text_about"; Notice the semi-colon at the end, this should be a less than sign (>), so the above line should be: <div id="text_about"> Also the following line has a bug: if($new == $new2 && !$new2=''){ You use the assignment operator (=) rather than the comparison operator (==). Use the following instead: if($new == $new2 && !empty($new2)){ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.