Tuesday, 21 May 2013
Friday, 3 May 2013
MyAccount- Change Password using PHP and MySQL code
Change Password Using PHP and MySQL.
If user wants to change their password then put update query of MySQL using PHP webpage scripting.
First Step to check weather user had input their old password, new password and confirm new password.
If not then give error message using PHP script.
After that check database connection and write query to update oldpass with newpass.
Here is the full code to change your password using PHP + MySQL.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> Change Password </title>
<?php
if(isset($_POST['submit']))
{
include('dbconn.php');
$old=trim($_POST['oldpass']);
$new=trim($_POST['newpass']);
$cnew=trim($_POST['cnewpass']);
if(empty($old))
{
echo "<p style='color:red;'> Please Enter Your Old Password </p>";
}
elseif(empty($new))
{
echo "<p style='color:red;'> Please Enter Desired New Password </p>";
}
elseif(empty($cnew))
{
echo "<p style='color:red;'> Please Enter Confirm New Password </p>";
}
elseif(strcmp($new,$cnew))
{
echo "<p style='color:red'> New Password And Confirm New Password Does Not Match </p>";
}
else
{
$sql="SELECT * FROM tbl_employer_reg WHERE password='$old'";
$result=mysqli_query($con,$sql);
$num_rows=mysqli_num_rows($result);
if($num_rows==1)
{
$sql="UPDATE `tbl_employer_reg` SET `password`= '$new' WHERE `password`= '$old'";
$r=mysqli_query($con,$sql);
echo "<p style='color:red;'> Your Password Has Been Changed</p>";
}
else
{
echo "<p style='color:red;'> Incorrect Password </p>";
}
}
$_POST['oldpass']="";
$_POST['newpass']="";
$_POST['cnewpass']="";
}
?>
</head>
<body>
<div style="width:520px;padding:10px;border:5px solid blue;margin:150px 250px;border-radius:25px;">
<h2 style="color:red"><center> CHANGE PASSWORD </center></h2>
<form name="change_pass" id="change_pass" method="post" action="">
<table border="0" cellpadding="6">
<tr>
<td style="color:#0000FF; font-weight:bolder; font-size:18px;">Enter Old Password : </td>
<td> <input type="password" name="oldpass" value="<?php if(isset($_POST['oldpass'])) {echo $_POST['oldpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td style="color:#0000FF; font-weight:bolder; font-size:18px;">Enter New Password : </td>
<td> <input type="password" name="newpass" value="<?php if(isset($_POST['newpass'])) {echo $_POST['newpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td style="color:#0000FF; font-weight:bolder;font-size:18px;">Confirm New Password : </td>
<td> <input type="password" name="cnewpass" value="<?php if(isset($_POST['cnewpass'])){echo $_POST['cnewpass'];} ?>" size="40" /></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" name="submit" value="SUBMIT" style="color:#0033FF;background-color:#CCCCCC; font-weight:bolder;font-size:22px" /> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
Learn PHP Project Training
visit website: Project Training Using PHP Technologies
Forgot Password Code for PHP + MySQL
Forgot Password PHP Language code.
If any user forgot their password then you can send them email orTo give them password on the same web page.
Here is the code which shows the password if user forgot it. Enter Username and Mobile no to show the password.
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Forgot Password </title>
<?php
if(isset($_POST['submit']))
{
include('myconnection.php');
$un=trim($_POST['username']);
$mn=trim($_POST['mobileno']);
if(empty($un))
{
echo "<p style='color:red;'> Please Enter Your UserName </p>";
}
elseif(empty($mn))
{
echo "<p style='color:red;'> Please Enter Your Mobileno </p>";
}
else
{
$sql="select `password` from tbl_employer_reg where `emailid`='$un' and `mobile`='$mn'";
$result=mysqli_query($con,$sql);
$num_rows=mysqli_num_rows($result);
if($num_rows==1)
{
while($line=mysqli_fetch_array($result))
{
echo "your Password is ".$line['password'];
}
}
else
{
echo "Invalid Username/Mobileno";
}
}
}
?>
</head>
<body>
<h2 style="color:red"><center> FORGOT PASSWORD </center></h2>
<form name="form" method="post" action="">
<table border="0" >
<tr>
<td >Enter Your Username: </td>
<td> <input type="text" name="username" value="" size="40" /></td>
</tr>
<tr>
<td >Enter your mobile no : </td>
<td> <input type="text" name="mobileno" value="" size="40" /></td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" name="submit" value="SUBMIT" /> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
Thursday, 2 May 2013
Delete record using php + MySQL
Delete Record Using PHP + MySQL.
If Any web programmer of Web Developer doing code for delete any record from the table then1. He/She must have to see all the records of the table
2. And select the record to delete and press on delete button.
3. After deleting the record he/she must have to see the records of the table.
Here is the full code to see the records from the table and search the user according to the username.
If records are not more then see all the records by search with empty textbox and click on SUBMIT button.
After Search Result is generated Press on Delete.
Table Name of MySQL is tblreg
Have columns
1. id
2. username
3. hobbies
4. gender
5. emailid
6. mobileno
1. showreg.php file code
<?php
if(isset($_GET['submit']))
{
$s=trim($_GET['search']);
$con=mysqli_connect(@"localhost","root","","phpdemo") or die("Unable to connect to the database of Mysql name : phpdemo");
if(empty($s))
{
$sql="select * from tblreg";
}
else
{
$sql="select * from tblreg where username='$s'";
}
echo "<center>";
echo "<h1 style=\"color:Yellow;background-color:Black \">Show Registration Details</h1>";
$result=mysqli_query($con,$sql);
echo "<table border=\"2\" style=\"color:Black;background-color:#ffffcc\">";
echo "<th>Userid</th><th>Username</th><th>Hobbies</th><th>Gender</th><th>Emailid</th><th>Mobileno</th>";
while($line= mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo $line['id'];
echo "</td>";
echo "<td>";
echo $line['username'];
echo "</td>";
echo "<td>";
echo $line['hobbies'];
echo "</td>";
echo "<td>";
echo $line['gender'];
echo "</td>";
echo "<td>";
echo $line['emailid'];
echo "</td>";
echo "<td>";
echo $line['mobileno'];
?>
<input type="text" name="chid" value="<?php echo $line['id']; ?>" />
<?php
echo "</td>";
echo '<td><b><font color="#663300"><a href="delete.php?id=' . $line['id'] . '">Delete</a></font></b></td>';
echo "</tr>";
}
echo "</table>";
}
?>
<body>
<form id="showform" name="showform" method="get" action="">
<input type="text" name="search" />
<input type="submit" name="submit" value="submit" />
</form>
To Delete Record of The User write code on delete.php File.2. delete.php After Deleting the record he/she must reach at showreg.php to see the records of the table tblreg.
<?php
$con=mysqli_connect(@"localhost","root","","phpdemo") or die("Unable to connect to the database of Mysql name : phpdemo");
$id = $_REQUEST['id'];
echo "id is $id<br>";
$sql="DELETE FROM `tblreg` WHERE `id`='$id'";
$result = mysqli_query($con,$sql) or die("Error in Deleting!!!");
header("Location: showreg.php");
?>
PHP code to send email
after hosting is done for your website.
you can send email by using the below code of mail function in PHP
<?php
if(isset($_POST['submit']))
{
$errors = '';
if(empty($_POST['name']) ||
empty($_POST['toemail'])||
empty($_POST['subject']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$myemail = $_POST['toemail'];//<-----Put Your email address here.
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br> Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n\n Subject: $subject \n\n Email: $email_address \n\n Message \n\n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo "<center><p style=\"color:Green\"> Thank you !!! We will come to you shortly</p></center>";
}
else
{
echo "<center><p style=\"color:Red\">".$errors."</p></center>";
}
}
?>
<html>
<head>
<title>Send email using php</title>
</head>
<body>
<form id="form" name="form" method="post" action="">
<center>
<table>
<tr><td>Enter emailid for To : </td><td><input type="text" name="toemail" /></tr>
<tr><td>Enter your Name : </td><td><input type="text" name="name" /></tr>
<tr><td>Enter your Email : </td><td><input type="text" name="email" /></tr>
<tr><td>Enter your Subject : </td><td><input type="text" name="subject" /></tr>
<tr><td>Enter your Message : </td><td><input type="text" name="message" /></tr>
<tr><td></td><td>
<input type="submit" name="submit" value="submit" /></tr>
</table>
</center>
</form>
</body>
</html>
you can send email by using the below code of mail function in PHP
<?php
if(isset($_POST['submit']))
{
$errors = '';
if(empty($_POST['name']) ||
empty($_POST['toemail'])||
empty($_POST['subject']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$myemail = $_POST['toemail'];//<-----Put Your email address here.
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br> Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n\n Subject: $subject \n\n Email: $email_address \n\n Message \n\n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo "<center><p style=\"color:Green\"> Thank you !!! We will come to you shortly</p></center>";
}
else
{
echo "<center><p style=\"color:Red\">".$errors."</p></center>";
}
}
?>
<html>
<head>
<title>Send email using php</title>
</head>
<body>
<form id="form" name="form" method="post" action="">
<center>
<table>
<tr><td>Enter emailid for To : </td><td><input type="text" name="toemail" /></tr>
<tr><td>Enter your Name : </td><td><input type="text" name="name" /></tr>
<tr><td>Enter your Email : </td><td><input type="text" name="email" /></tr>
<tr><td>Enter your Subject : </td><td><input type="text" name="subject" /></tr>
<tr><td>Enter your Message : </td><td><input type="text" name="message" /></tr>
<tr><td></td><td>
<input type="submit" name="submit" value="submit" /></tr>
</table>
</center>
</form>
</body>
</html>
Subscribe to:
Posts (Atom)