i had created a form ! having
three text box
Old password
New password
Confim new password!!
it is being validated by javascript with the following fuction -
<script language="javascript">
-
-
function checkempty(obj,msg){
-
if(obj.value==''){
-
alert(msg);
-
obj.focus()
-
return false;
-
}
-
return true;
-
}
-
function confirmpass(obj,obj1,msg){
-
if(obj1.value!=obj.value){
-
alert(msg);
-
obj1.select()
-
obj1.focus()
-
return false;
-
}
-
return true;
-
}
-
function chkChangePass(){
-
if(checkempty(document.frmChangePass.oPass,"Information: Enter Old Password")==false) return false;
-
if(checkempty(document.frmChangePass.NPass,"Information: Enter New Password")==false) return false;
-
if(checkempty(document.frmChangePass.CNPass,"Information: Confirm New Password")==false) return false;
-
if(confirmpass(document.frmChangePass.NPass,document.frmChangePass.CNPass,"Information: New and Confirm Password should be same")==false) return false;
-
return true;
-
}
-
</script>
-
The form code is as follow -
<form name="frmChangePass" method="post" action="Changepass.php?action=Confirm&id=1" onSubmit="return chkChangePass();">
-
-
<table width="100%" border="0" cellspacing="2" cellpadding="1">
-
<tr bordercolor="#CCCCCC">
-
<td width="30%">Old Password:</td>
-
<td width="70%" align="left" valign="middle"><input name="oPass" type="password" onfocus="this.select();" value="<?php if(isset($_REQUEST["oPass"])){print $_REQUEST["oPass"];}?>" style="BORDER-WIDTH:1;BORDER-STYLE:dashed;border-color:000000;background:eeeeee;font-size:10px;color:000000;height:20;width:150" id="oPass" size="54" /></td>
-
</tr>
-
<tr bordercolor="#CCCCCC">
-
<td>New Password: </td>
-
<td align="left" valign="middle"><input name="NPass" type="password" onfocus="this.select();" value="<?php if(isset($_REQUEST["NPass"])){print $_REQUEST["NPass"];}?>" style="BORDER-WIDTH:1;BORDER-STYLE:dashed;border-color:000000;background:eeeeee;font-size:10px;color:000000;height:20;width:150" id="NPass" size="54" /></td>
-
</tr>
-
<tr bordercolor="#CCCCCC">
-
<td>Confirm New Password: </td>
-
<td align="left" valign="middle"><input name="CNPass" type="password" onfocus="this.select();" value="<?php if(isset($_REQUEST["CNPass"])){print $_REQUEST["CNPass"];}?>" style="BORDER-WIDTH:1;BORDER-STYLE:dashed;border-color:000000;background:eeeeee;font-size:10px;color:000000;height:20;width:150" id="CNPass" size="54" /></td>
-
</tr>
-
-
<tr bordercolor="#FFFFFF" bgcolor="<?php echo $rClr?>">
-
<td align="left" valign="middle" bordercolor="#CCCCCC" bgcolor="<?php echo $rClr?>" class="welcome"> </td>
-
<td align="left" valign="middle" bordercolor="#CCCCCC" bgcolor="<?php echo $rClr?>" class="Vkasimp"><input type="submit" name="Submit2" value="Change Pass" style="BORDER-WIDTH:1;BORDER-STYLE:double;border-color:000000;background:eeeeee;font-size:10px;color:000000;height:20;width:150" /></td>
-
</tr>
-
</table>
-
</form>
-
-
according to action of the form on submission the below code is executed
it get the id,old password and new password
and execute the update query -
-
<?php }if($action=="Confirm"){
-
$id=$_GET['id'];
-
$oldpassword=$_POST['oPass'];
-
$CNpassword=$_POST['CNPass'];
-
-
$update= "Update `users` Set `user_pass`='$CNpassword' Where `campus_id`=1 AND `user_pass`='$oldpassword'";
-
$result=mysql_query($update) or die(mysql_error());
-
-
php echo "<strong>Password successfully changed</strong>";
-
}
-
if the old password is wrong or unmatched the query does not executes and password is not changed in the data base i want to make check that if the query is not executed or the password is not changed due to unmatched old password than it should display
old password incorrect please correct it again
else it shows password changed successfully
my code simply show password changed successfully!! on both states!
i had used if else but not working
please help me
13 9035 Atli 5,058
Expert 4TB
Show us what you tried.
When you want to check how many rows were successfully updated with an UPDATE query, you should use the mysql_affected_rows function. People often mistakenly use the mysql_num_rows function, but that function only counts the number of rows returned, and an UPDATE query never returns any rows.
i have only 1 row in the table simply
can u tell what would be the return type of the mysql affected rows function ?
can it be done like this - <?php }if($action=="Confirm"){
-
$id=$_GET['id'];
-
$oldpassword=$_POST['oPass'];
-
$CNpassword=$_POST['CNPass'];
-
-
$update= "Update `users` Set `user_pass`='$CNpassword' Where `campus_id`=1 AND `user_pass`='$oldpassword'";
-
$result=mysql_query($update) or die(mysql_error());
- if(mysql_affected_rows ($result) == false)
-
{
-
echo "<strong> Old password wrong please retype it again<</strong>";
-
}
-
else
-
{
-
echo "<strong>Password successfully changed</strong>";
-
}
-
?>
-
</td>
-
</tr>
-
</table>
-
<?php }?>
Atli 5,058
Expert 4TB
To quote the manual (the link I posted earlier
Meaning, if you are expecting the query to affect one row, you would check to see if the function returns 1. If it does not then the query did not work as expected.
can you elaborate a little more so that i can reach with a solution
Atli 5,058
Expert 4TB
You use the mysql_affected_rows function on the result of a mysql_query call to find out how many rows the query affected.
In your case, you need to find out if the query affected any rows at all, so you use it to see if one or more rows were affected. If there were one ore more rows affected, you print the success message. Otherwise you print an error message.
In simple pseudo-code, you could write that as: - rowsAffected = mysql_affected_rows(result)
-
if rowsAffected > 0
-
Print success message
-
else
-
Print error message
my $result= mysql_query("Query")
rowsAffected = mysql_affected_rows($result)
if rowsAffected > 0
Print success message
else
Print error message
it gives error
Warning: mysql_affected_rows(): supplied argument is not a valid
This is a common error,
whereas mysql_num_rows expects a result resource,
mysql_affected_rows() expects a link (database) resource.
i.e the return from mysql_connect()
Atli 5,058
Expert 4TB
O yea, that's right. I forgot that it took the database link, rather than the query result. Haven't worked with the old mysql functions in ages :)
so any other suggestion!!
mysql_query returns 1 on both condition whether the row is effected or not
Atli 5,058
Expert 4TB
Another suggestion isn't needed. The one we've been talking about works fine, you just need to use the database link in the mysql_affected_rows() function rather than the query result.
ok i had got the solution with another logic thanks for you both for cooperation
i had checked firstly the old password from the database by fetching the value
then i compared and used if else simply
Also keep in mind, if the user sets the password to his old password (i.e. you update a row, say...first_name to John when it's already set to John) the affected rows will be zero even though in some cases this is what you expect, "a blind update".
So I wouldn't build an if statement around an update query that expects it to always return a value greater than zero.
Just a thought - basing an update on "where password =" is a tad risky. If your passwords are not unique, you will update all records with the same password, and if passwords are unique, you have opened a possibility for someone to figure out existing passwords.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vishal |
last post by:
hi
i am building aan application which will send mail to user when he
registers on my site and i am checking whther the email id is working
properly or not by sending his email and then cheking...
|
by: Siu |
last post by:
Hi,
in my ASP.NET (C#) application I would like to check in advance if a node
exist: my code is as follow:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(XML_FILENAME);
XmlNode...
|
by: kiran |
last post by:
How to check whether the given application is running or not in the current
machine. From, my cshartp program I want check whether the yahoo messenger
process is running ro not..? if the process is...
|
by: Jiho Han |
last post by:
What is the best way to check whether the page is simply a postback or the
form has been submit with the intention of doing something?
In the olden days, I used to check for a form field name...
|
by: zimmy |
last post by:
Hi,
Is it possible to check whether ASP.NET is installed on a machine,
within a program that I'm writing in C#? And if it's installed, can I
check if it is enabled? How?
Thanks
|
by: ItsMe |
last post by:
Hi,
I've 50 MDI Forms in my project, so trying to create MDI Child Form from
this procedure.
But the problem is, unable to declare as "NewFormName". It gives me an
error. Is there any
other...
|
by: SoFaraway |
last post by:
Dear all,
In C, how do we check whether a string starts with a substring? E.g.,
char *str = ...;
char *substr = ...;
How do we check whether str starts with substr?
Thank you very much!
|
by: foolsmart2005 |
last post by:
There are 10 webpages on the host,
e.g. 001.html, 002.html, 003,html, 004.html, ......010.html
I want to check whether the page is the last page. How can I do.
In the index.html
-Go to last...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |