Jump to content

problem in change password function


heshan

Recommended Posts

Hi guys,

 

I have a problem in "change password" function. The below code does not support "change password" thing. Can anyone help me out?

 

changePasword.php

 

<form id="form1" name="form1" method="post" action="changePasworddb.php">
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);
?>
<table width="850" border="1" align="center" bgcolor="#00FFFF">
  </table></td>
  </tr>
  <tr>
    <td width="170"> </td>
    <td width="664"><table width="660" border="0">
      <tr>
        <td width="124"> </td>
        <td width="124"> </td>
        <td width="124"> </td>
        <td width="124" align="center">Change Password</td>
        <td width="129" align="center"><a href="../Home page/new student registration/signout.php">Signout</a></td>
      </tr>
    </table></td>
  </tr>
  
     <tr>
        <td> </td>
        <td><label>Current password</label>
           </td>
        <td colspan="2">
<?php
	  
$query="SELECT username,password FROM administrator ";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
  $username=$row['username'];
  $password=$row['password'];
}

echo $password;
?></td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td><input type="hidden" name="grade" value="<?php echo $username;?>"/></td>
        <td><input type="hidden" name="grade" value="<?php echo $password;?>"/></td>
        <td width="85">
          <input type="submit" name="button" id="button" value="Save" onClick="return Validate1();"/>
        </td>
        <td width="120">
          <input type="button" name="button2" id="button2" value="Reset" onClick="return Validate();"/>
        </td>
      
</table>
</form>

 

changePasworddb.php

 

<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);

$username=$_POST['username'];
$password=$_POST['password'];
$newpassword=$_POST['newpassword'];

$query="UPDATE administrator SET password='$newpassword' where username='$username'";
$result=mysql_query($query) or die (mysql_error());
header("location:add techer/addAdminterpage.php");
exit();
?>

Link to comment
Share on other sites

Herewith i re-submit my form..

 

Actually what is happening is after change an existing password and click on "save" button the data is saved.(no error messages) But in the database the old password is still showing. But what i actually want is to replace the old password  with the new password.

 

<form id="form1" name="form1" method="post" action="changePasworddb.php">
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);
?>
<table width="850" border="1" align="center" bgcolor="#00FFFF">
  <tr>
    <td colspan="2"><table width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <td width="25%"><img src="../IMAGE/banner - Copy.jpg" width="186" height="136" /></td>
        <td width="75%" align="center" valign="middle"><div align="center"><img src="../IMAGE/banner.jpg" width="733" height="137" /></div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="170"> </td>
    <td width="664"><table width="660" border="0">
      <tr>
        <td width="124"><a href="../Home page/new student registration/add_or_manage.php">Manage Data</a></td>
        <td width="124"> </td>
        <td width="124"> </td>
        <td width="124" align="center">Change Password</td>
        <td width="129" align="center"><a href="../Home page/new student registration/signout.php">Signout</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="59" valign="top"><ul id="MenuBar1" class="MenuBarVertical">
      <li><a href="../../add admin users/add techer/addAdminUser.php">Add Admin Login</a> </li>
      <li><a href="../../Student registration/new student registration/newStudentRegistrationForm.php">Add Student</a></li>
      <li><a href="../../student attendance/add attendance/addStudentAttendance.php">Add Student Attendance</a> </li>
      <li><a href="../../Student time table/add1 time table/addTimeTable.php">Add Time Table</a></li>
      <li><a href="../../Student marks/add student marks/addStudentMark.php">Add Student Marks</a></li>
      <li><a href="../../manage subject/add subject.php">Add Subject</a></li>
      <li><a href="../../search student information/SearchStudentInformation.php">Search Student Information</a></li>
      <li><a href="../../student payments reports/studentsPayments.php">Student Payment Reports</a></li>
      <li><a href="../../Issue certificate/issueCertificate.php">Issue Certificates</a></li>
    </ul>
      <p> </p>
    <p> </p></td>
    <td valign="top"><table width="659" border="0">
      <tr>
        <td width="16"> </td>
        <td width="147"> </td>
        <td colspan="2"> </td>
        <td width="124"> </td>
        <td width="125"> </td>
      </tr>
      <tr>
        <td> </td>
        <td colspan="3"><h3>
          <label>Change Password</label>
           </h3></td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td colspan="2"> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td><label>Current password</label>
           </td>
        <td colspan="2">
<?php
	  
$query="SELECT username,password FROM administrator ";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
  $username=$row['username'];
  $password=$row['password'];
}

echo $password;
?></td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td colspan="2"> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td><label>New password</label>
           </td>
        <td colspan="2">
          <input type="password" name="newpassword" id="textfield2" />
        </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td colspan="2"> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td><label>Confirm password</label> </td>
        <td colspan="2">
          <input type="password" name="confirmpassword" id="textfield3" />
        </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td colspan="2"> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td><input type="hidden" name="grade" value="<?php echo $username;?>"/></td>
        <td><input type="hidden" name="grade" value="<?php echo $password;?>"/></td>
        <td width="85">
          <input type="submit" name="button" id="button" value="Save" onClick="return Validate1();"/>
        </td>
        <td width="120">
          <input type="button" name="button2" id="button2" value="Reset" onClick="return Validate();"/>
        </td>
        <td> </td>
        <td> </td>
      </tr>
    </table>
      <p> </p>
    <p> </p></td>
  </tr>
</table>
</form>

Link to comment
Share on other sites

like i said in my previous comment, you are not posting username over to the changepasswordDb. you have two hidden fields with the name set to grade, not username and password. so you are in effect telling the query to

$query="UPDATE administrator SET password='$newpassword' where username=''";

 

so it will never update. change the input names from grade to username and password accordingly

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.