473,881 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check whether query executed or not

78 New Member
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

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  3. function checkempty(obj,msg){
  4.     if(obj.value==''){
  5.         alert(msg);
  6.         obj.focus()
  7.         return false;
  8.     }
  9.     return true;
  10. }
  11. function confirmpass(obj,obj1,msg){
  12.     if(obj1.value!=obj.value){
  13.         alert(msg);
  14.         obj1.select()
  15.         obj1.focus()
  16.         return false;
  17.     }
  18.     return true;
  19. }
  20. function chkChangePass(){
  21.     if(checkempty(document.frmChangePass.oPass,"Information: Enter Old Password")==false) return false;
  22.     if(checkempty(document.frmChangePass.NPass,"Information: Enter New Password")==false) return false;
  23.     if(checkempty(document.frmChangePass.CNPass,"Information: Confirm New Password")==false) return false;
  24.     if(confirmpass(document.frmChangePass.NPass,document.frmChangePass.CNPass,"Information: New and Confirm Password should be same")==false) return false;
  25.     return true;
  26. }
  27. </script>
The form code is as follow
Expand|Select|Wrap|Line Numbers
  1. <form name="frmChangePass" method="post" action="Changepass.php?action=Confirm&amp;id=1" onSubmit="return chkChangePass();">
  3.           <table width="100%" border="0" cellspacing="2" cellpadding="1">
  4.               <tr bordercolor="#CCCCCC">
  5.                 <td width="30%">Old Password:</td>
  6.                 <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>
  7.               </tr>
  8.               <tr bordercolor="#CCCCCC">
  9.                 <td>New Password: </td>
  10.                 <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>
  11.               </tr>
  12.               <tr bordercolor="#CCCCCC">
  13.                 <td>Confirm New Password: </td>
  14.                 <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>
  15.               </tr>
  17.               <tr bordercolor="#FFFFFF" bgcolor="<?php echo $rClr?>">
  18.                 <td align="left" valign="middle" bordercolor="#CCCCCC" bgcolor="<?php echo $rClr?>" class="welcome">&nbsp;</td>
  19.                 <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>
  20.               </tr>
  21.             </table>
  22.             </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

Expand|Select|Wrap|Line Numbers
  2. <?php }if($action=="Confirm"){
  3. $id=$_GET['id'];
  4. $oldpassword=$_POST['oPass'];
  5. $CNpassword=$_POST['CNPass'];
  7. $update= "Update `users` Set `user_pass`='$CNpassword' Where `campus_id`=1 AND `user_pass`='$oldpassword'";
  8. $result=mysql_query($update) or die(mysql_error()); 
  10. php echo "<strong>Password successfully changed</strong>"; 
  11. }

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
Apr 12 '10 #1
13 9199
5,058 Recognized Expert Expert
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.
Apr 12 '10 #2
78 New Member
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

Expand|Select|Wrap|Line Numbers
  1. <?php }if($action=="Confirm"){
  2. $id=$_GET['id'];
  3. $oldpassword=$_POST['oPass'];
  4. $CNpassword=$_POST['CNPass'];
  6. $update= "Update `users` Set `user_pass`='$CNpassword' Where `campus_id`=1 AND `user_pass`='$oldpassword'";
  7. $result=mysql_query($update) or die(mysql_error()); 
  8. if(mysql_affected_rows ($result) == false)
  9. {
  10.  echo "<strong> Old password wrong please retype it again<</strong>"; 
  11. }
  12. else
  13. {
  14.  echo "<strong>Password successfully changed</strong>"; 
  15. }
  16. ?>
  17. </td>
  18.   </tr>
  19. </table>
  20. <?php }?>
Apr 12 '10 #3
5,058 Recognized Expert Expert
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.
Apr 12 '10 #4
78 New Member
can you elaborate a little more so that i can reach with a solution
Apr 12 '10 #5
5,058 Recognized Expert Expert
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:
Expand|Select|Wrap|Line Numbers
  1. rowsAffected = mysql_affected_rows(result)
  2. if rowsAffected > 0
  3.     Print success message
  4. else
  5.     Print error message
Apr 12 '10 #6
78 New Member
my $result= mysql_query("Qu ery")
rowsAffected = mysql_affected_ rows($result)
if rowsAffected > 0
Print success message
Print error message

it gives error

Warning: mysql_affected_ rows(): supplied argument is not a valid
Apr 12 '10 #7
code green
1,726 Recognized Expert Top Contributor
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()
Apr 12 '10 #8
5,058 Recognized Expert Expert
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 :)
Apr 12 '10 #9
78 New Member
so any other suggestion!!

mysql_query returns 1 on both condition whether the row is effected or not
Apr 12 '10 #10

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 whether the email was rebound or not. i know something about how to send email in php using mail function but not everything about sending email.
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 nodeApplication = xmlDoc.SelectSingleNode(xmlPath); Before launching the instruction xmlDoc.SelectSingoleNode(xmlPath), how would like to check if my xmlPath exists in the Xml document... it is a soft
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 running i want to open the yahoo messenger application through my csharp program.. I tried using Win32 API "ShowWindow" function , but it is not opening or showing hidden applications. How can I do this..?
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 used for the submit button: <input type="submit" name="saverecord" value="push me to save"> Then I'd retrieve it using something like:
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 better way. And I would like to check whether the form already exist or not. ? Or else what's happening is, it opens many forms as the user clicks. Any ideas ?
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 page,<---- I want to link this to the last page(010.html). Can I do it? How? Thanks!
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.