Change Password
Posted: Wed Mar 07, 2012 1:13 am
Hi! Im new in php and i try to make a registration system.I have this code that i used that i got from different tutorial site.But my problem is my change password script doesnt work. Please help me.I wanna learn!
change2.php (My change password script)
editsavepass.php (My verification)
change2.php (My change password script)
Code: Select all
<?php
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
include ('data_con.php');
if (isset($_POST['submit'])) {
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields.<a href="change2.php">Back.</a>');
}
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}
$_POST['pass'] = ($_POST['pass2']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass2']);
$_POST['username'] = addslashes($_POST['username']);
}
$insert = "INSERT INTO users (username,pass,pass2)
VALUES('".$_POST['username']."','".$_POST['pass']."','".$_POST['pass']."','2')";
mysql_query($insert);
?>
<?php
} else {
?>
<?php
echo "<form method=post name=f1 action='editsavepass.php'>";
echo "<input name = username id = username readonly type='hidden' ><br><br><br>";
echo "<center>";
//echo "Enrollment no : " . "$row[1] <br><br><br>";
echo "<font color = red> New Password </font> : " . "<input type=password name=pass size=40 maxlength=40><br><br><br>";
//echo "Street : " . "$row[12] <br><br><br>";
echo "<font color = red> Confirm Password </font> : " . "<input type=password name=pass2 size=40 maxlength=40><br><br><br>";
echo "<input type=submit value=Submit>";
echo "</center>";
echo "</form>";
}
}
else
{
}
?>
Code: Select all
<?php
$username=$_REQUEST['username'];
$pass=$_REQUEST['pass'];
$pass2=$_REQUEST['pass2'];
$link=mysql_connect("localhost","root","") or die("Cannot Connect to the database!");
mysql_select_db("nstpreg",$link) or die ("Cannot select the database!");
$Query="UPDATE users SET pass='".$pass."', pass2='".$pass2."' WHERE username='".$username."'";
if(!mysql_query($Query,$link))
{die ("An unexpected error occured while saving the record, Please try again!<a href='all.php'>Go Back </a>");}
else
{
echo "Record updated successfully!<a href='profile.php'>Go Back </a>";}
?>