473,770 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check this valus against mysql

mmarif4u
23 New Member
Hi everybody...

I want to enter values to db like the following,,,
Format is like this (810605-14-6356)
This is the rite format, No a to z letters...
6 digits then - then 2 digits then - then 4 digits.

Expand|Select|Wrap|Line Numbers
  1.  dbConnect('db');
  2.  
  3.    $ic = $_POST['icnumber'];
  4.  
  5.    if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) { 
  6.     //$ic is valid
  7.     error ('IC Number is not in right format.\\n'.
  8.               'Please enter IC Number agian.');
  9.      }
  10.  
  11.    if ($ic==''
  12.       or $_POST['cicnumber']=='' )  { 
  13.          error ('One or more required fields were left blank.\\n'.
  14.               'Please fill them in and try again.');
  15.     }
  16.     // this makes sure both passwords entered match
  17.    if ($ic != $_POST['cicnumber']) {
  18.    error ('Your IC Numbers not matched.\\n'.
  19.               'Please try again.');
  20.    }
  21.  
  22.     // Check for existing user with the ic number
  23.     $sql = "SELECT COUNT(*) FROM m_users WHERE icnumber = $ic ";
  24.     $result = mysql_query($sql);
  25.     if (!$result) {    
  26.         error('A database error occurred in processing your '.
  27.               'submission.\\nIf this error persists, please '.
  28.               'contact you@example.com.');
  29.     }
  30.  
  31.     if (mysql_result($result,0,0)>0) {
  32.         error('A user already exists with your chosen IC Number.\\n'.
  33.               'Please try your own IC Number.');
  34.     }
  35.  
  36.  
  37.     $random = rand(1000000,9999999990);  
  38.  
  39.  
  40.     $sql = "INSERT INTO m_users SET
  41.               icnumber = ('$ic'),
  42.               acccode = ('$random'),
  43.               actdate = curdate(),
  44.               expdate = DATE_ADD(curdate(), INTERVAL 1 month);
  45.               ";
  46.     if (!mysql_query($sql))
  47.         error('A database error occurred in processing your '.
  48.               'submission.\\nIf this error persists, please '.
  49.               'contact admin@straight-a.com.my .\\n' . mysql_error());
  50.  
  51.     ?>
  52.  
I make this code for it,, but its not working can anyone help me...

Expand|Select|Wrap|Line Numbers
  1. $ic = $_POST['icnumber'];
  2.  
  3.    if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) { 
  4.     //$ic is valid
  5.     error ('IC Number is not in right format.\\n'.
  6.               'Please enter IC Number agian.');
  7.      }
  8.  
Thanks in advance.
Jan 3 '07 #1
8 1929
cassbiz
202 New Member
Have you thought about creating three different fields in your MySQL table then in regards to the form separate it with three different fields. This way it will be able to read all the numbers simply without complicated code.
Jan 3 '07 #2
ronverdonk
4,258 Recognized Expert Specialist
Special chars, when taken literally, must be escaped. You must escape the hyphens in your pattern with a backslash. Like
Expand|Select|Wrap|Line Numbers
  1. [0-9]{6}\-[0-9]{2}\-[0-9]{4}
Ronald :cool:
Jan 3 '07 #3
mmarif4u
23 New Member
Thanks Ronald the problem is not solved with that.
i dont know why....
Plz help me out of this prob.

Thanks...
Jan 4 '07 #4
ronverdonk
4,258 Recognized Expert Specialist
I did not show the full expression, just a sample of using literals. Here is the full test[php]if (preg_match('^\ d{6}\-\d{2}\-\d{4}$^', $test)) {
echo "Matched on $test<br />";
}
else {
echo "Failed match on $test<br />";
}[/php]
Ronald :cool:
Jan 4 '07 #5
mmarif4u
23 New Member
Thanks Ronald For reply have a great 2007.

I am now far away From my PC.
i will test it later..
But u use \d except of [0-9] ,, it will work..
I dont want to echo if the icnumber format is correct but if
wrong then error(i have common.php in which i call error mag), not echo..

Thanks again for ur help..
Jan 4 '07 #6
ronverdonk
4,258 Recognized Expert Specialist
It is just a working sample to show you how to test it.You can adapt it to your heart's delight.

Ronald :cool:
Jan 4 '07 #7
mmarif4u
23 New Member
Thanks Ronald for help..

I will test this, if any problem i will post reply...

Thanks
Jan 4 '07 #8
mmarif4u
23 New Member
Thanks Ronlad for ur help.
i make some changes in it.. and now it is working..

Expand|Select|Wrap|Line Numbers
  1. if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) { 
  2.  
  3.     }
  4.     else {      
  5.     error('IC Number format is not Valid.\\n'.
  6.               'Please try again.');
  7.        }
  8.  
Thanks again for ur kind work on this prob...
Jan 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1629
by: Garp | last post by:
Everyone, I know there's no comp.databases.mysql group, but if there's the demand for questions about phrasing queries and the like that aren't PHP related (and there is - every other q. seems to be), why isn't one created? I haven't done that for a while, but why hasn't this already been done? Garp
2
1720
by: Jeroen | last post by:
I am developing an asp.net website with windows authentification and I want to check to which group the user belongs. I know how to check for the user that has logged in and to see if he belongs to a group that was predefined by windows but I need to know all the groups he belongs to (also the ones that I created myself). Please help me with this, I'm going crazy ! Thanks,
1
1047
by: Jake | last post by:
Hello, I am developing an application and there is a specific area in which I want a specific group of windows users to access only. The users belong to a group called Security1. How can I test to see if a user belongs to this group and if so enable the button? Thanks in advance. Jake
3
4313
by: Rich | last post by:
The procedure below checks if a character entered into a cell of a datagridview is contained in a string array of valid characters for this particular cell. It seems kludgy. I am asking what the best practice would be. I was thinking I could use an arrayList which has the "contains" property and do this: If not arr.Contains(s1) then --- don't continue but my list of codes might be about 50 char combinations. So I was thinking a...
2
2532
by: JasonC | last post by:
Hi, First time posting here so please be gentle! I wish to check a variable for a number of words that are in a array. Not sure if this is the best way to do it, but this is what i have. I have my own counter system that counts every visitor, but some of these visits are from BOTS, spiders..
2
2762
by: rote | last post by:
My sceanrio is this on an asp.net 2.0 freamework. I want to use any of the data controls e.g Gridview,DetailView etc.. But i want some buttons e.g update,edit save etc to be enable or disabled based on if they belong to some security groups in active directory. I'm looking for the best options for this because i want to store those security groups somewhere and then check for the user against those security groups for their authorisation...
17
3260
by: wswilson | last post by:
In python, I could write: a = 1 if a in : do something... In c (and many other languages):
2
2305
by: marioliveira | last post by:
I have a orm built with RSForms Pro in which there is a calendar. The form is about bookings for activities, some of which are not available every weekday. Is there a way of checking the date the clients chooses and display some kind of alert in case the activity he/hse is booking, does not take place in that weekday?
9
3056
doma23
by: doma23 | last post by:
This thread was taken from a post in Nz function not working and refers to comments in post #4. Yeah, I was thinking if you could share that API function you have, because I was searching for a way to verify the user's win password in access for some time now.
0
9602
marktang
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...
0
9439
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,...
0
10071
jinu1996
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...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
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...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
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...
1
3987
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
3
2832
bsmnconsultancy
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.