Change Pincode
Change Pincode:
by request,
save this as chpin.php
Code
<?php
include("config.php");
if($logged[username])
{
switch($_GET[page])
{
default:
echo ("
<strong>Change Pincode:</strong>
<form method=\"post\" action=\"?page=change\">
<table>
<tr>
<td>Current Pincode:</td>
<td><input name=\"current\" type=\"password\"></td>
</tr>
<tr>
<td>New Pincode:</td>
<td><input name=\"new\" type=\"password\"></td>
</tr>
<tr>
<td></td>
<td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
</tr>
</table>
</form>
");
break;
case 'change':
$current = "$_POST[current]";
$new = "$_POST[new]";
$sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$profile = mysql_fetch_array($sql);
if($current == NULL || $new == NULL)
{
die ("All fields are required.");
}
if($current != $profile[pincode])
{
die ("Your current password does not match the posted password.");
}
else
{
$sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
echo ("Pincode successfully changed.");
}
break;
}
}
else
{
echo ("Please login.");
}
?>
Define:
Code
<?php
include("config.php");
if($logged[username])
{
switch($_GET[page])
{
Includes our database connection, checks if user is logged in, and makes it ?page=
Code
<strong>Change Pincode:</strong>
<form method=\"post\" action=\"?page=change\">
<table>
<tr>
<td>Current Pincode:</td>
<td><input name=\"current\" type=\"password\"></td>
</tr>
<tr>
<td>New Pincode:</td>
<td><input name=\"new\" type=\"password\"></td>
</tr>
<tr>
<td></td>
<td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
</tr>
</table>
</form>
Our change pincode form.
Code
break;
case 'change':
Closes off our default page. Then makes the page ?page=change.
Code
$current = "$_POST[current]";
$new = "$_POST[new]";
$sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$profile = mysql_fetch_array($sql);
Defines our variables. And grabs the members information from the database.
Code
if($current == NULL || $new == NULL)
{
die ("All fields are required.");
}
Makes sure that the two fields aren't empty.
Code
if($current != $profile[pincode])
{
die ("Your current password does not match the posted password.");
}
Makes sure that the posted current password is the same as in the database. (Security Reasons).
Code
else
{
$sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
echo ("Pincode successfully changed.");
}
break;
Inserts the users new pincode. Gives a success message. and closes off the ?page=change section.
Code
}
}
else
{
echo ("Please login.");
}
?>
Closes the ?page= function and closes off the logged in section. shows if the user is not logged in. And turns off the php coding.
Thats it for the tut.
be sure to look out for more by me.