Garloz Posted March 29, 2010 Share Posted March 29, 2010 Hi, im so stuck in here. Like i have code like this(called update.php). <?php $username = $_POST['user']; $password = $_POST['vanaparool']; $password2 = $_POST['uusparool']; $con = mysql_connect("localhost","baasiksutaja","parool"); if (!$con) { die('Could not connect: ' . mysql_error()); } // vastus mysql_select_db(baasinimi); $uuendamine = mysql_query("SELECT * FROM testtable WHERE (username='$username' AND password='$password')"); while($row = mysql_fetch_array($uuendamine)) { echo "Your " . $row['username'] . " password is updated!" ; } // uuendamine mysql_select_db(baasinimi); mysql_query("UPDATE testtable set password='$password2'"); mysql_close($con); ?> And my other code: <form method="post" action="update.php"> <table width="80%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms"> <tr> <td width="31%">Username:</td> <td width="69%"><input name="user" type="text" id="user"></td> </tr> <tr> <td width="31%">Old password:</td> <td width="69%"><input name="vanaparool" type="password" id="vanaparool"></td> </tr> <tr> <td>New password:</td> <td width="69%"><input name="uusparool" type="password" id="uusparool"></td> </tr> </table> <p align="center"> <input name="uuenda" type="submit" id="uuenda" value="Update"> </p> My problem is: How could i set them in one page? * If i "update" then if it's not succesfully updated - prints me error(not blank page). * So if I submit - then it shows above the "form" - "Successfully updated" or "Error! Check username and password". Quote Link to comment Share on other sites More sharing options...
GetPutDelete Posted March 29, 2010 Share Posted March 29, 2010 I'm a little confused with what you are asking, do you want to POST the form to the same page and have the same page process the data? Quote Link to comment Share on other sites More sharing options...
Garloz Posted March 29, 2010 Author Share Posted March 29, 2010 I'm a little confused with what you are asking, do you want to POST the form to the same page and have the same page process the data? Yeah, that is one what I want to do. About like this: http://war3ftest.pri.ee/admininfo.php Quote Link to comment Share on other sites More sharing options...
GetPutDelete Posted March 29, 2010 Share Posted March 29, 2010 Here you go... <?php if(isset($_POST['user']) && isset($_POST['vanaparool']) && isset($_POST['uusparool'])) { $username = $_POST['user']; $password = $_POST['vanaparool']; $password2 = $_POST['uusparool']; $con = mysql_connect("localhost","baasiksutaja","parool"); if (!$con) { die('Could not connect: ' . mysql_error()); } // vastus mysql_select_db(baasinimi); $uuendamine = mysql_query("SELECT * FROM testtable WHERE (username='$username' AND password='$password')"); while($row = mysql_fetch_array($uuendamine)) { echo "Your " . $row['username'] . " password is updated!" ; } // uuendamine mysql_select_db(baasinimi); mysql_query("UPDATE testtable set password='$password2'"); mysql_close($con); } ?> <form method="post" action=""> <table width="80%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms"> <tr> <td width="31%">Username:</td> <td width="69%"><input name="user" type="text" id="user"></td> </tr> <tr> <td width="31%">Old password:</td> <td width="69%"><input name="vanaparool" type="password" id="vanaparool"></td> </tr> <tr> <td>New password:</td> <td width="69%"><input name="uusparool" type="password" id="uusparool"></td> </tr> </table> <p align="center"> <input name="uuenda" type="submit" id="uuenda" value="Update"> </p> </form> The form now posts to itself. When the page loads again it checks for POST data and if there is some it runs the code to update the users details. Quote Link to comment Share on other sites More sharing options...
Garloz Posted March 29, 2010 Author Share Posted March 29, 2010 Thanks. It's in one page now. But it's seems that it doesnt update my database. How could I add this that it will update password and echo answer if updated or not updated? Quote Link to comment Share on other sites More sharing options...
GetPutDelete Posted March 29, 2010 Share Posted March 29, 2010 Are you sure the database login details are correct? Quote Link to comment Share on other sites More sharing options...
Garloz Posted March 29, 2010 Author Share Posted March 29, 2010 Are you sure the database login details are correct? Yes. Maybe I have some bug in this code? I want like, user writes his username- password - new password to form. PHP check if the username with that password exist - if yes, then update the old password with new one for this user. And then displays above the form, like "Your password is changed" and if the username-password are incorrect then "Username/Password doesnt match". Ah yeah, should I add mysql_real_escape_string too? Quote Link to comment Share on other sites More sharing options...
Garloz Posted March 29, 2010 Author Share Posted March 29, 2010 Anyone?? I try to make this kind of script like this is: [link] "adminni nimi" means "username" "vana adminni parool" means "old password" "uus adminni parool" means "new password" Anyone helps plz? 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.