473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to check this valus against mysql

mmarif4u
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 1912
cassbiz
202 100+
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 Expert 4TB
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
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 Expert 4TB
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
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 Expert 4TB
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
Thanks Ronald for help..

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

Thanks
Jan 4 '07 #8
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
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...
2
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...
1
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...
3
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...
2
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. ...
2
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...
17
by: wswilson | last post by:
In python, I could write: a = 1 if a in : do something... In c (and many other languages):
2
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...
9
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.