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.
I make this code for it,, but its not working can anyone help me...
Thanks in advance.
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.
Code:
dbConnect('db');
$ic = $_POST['icnumber'];
if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {
//$ic is valid
error ('IC Number is not in right format.\\n'.
'Please enter IC Number agian.');
}
if ($ic==''
or $_POST['cicnumber']=='' ) {
error ('One or more required fields were left blank.\\n'.
'Please fill them in and try again.');
}
// this makes sure both passwords entered match
if ($ic != $_POST['cicnumber']) {
error ('Your IC Numbers not matched.\\n'.
'Please try again.');
}
// Check for existing user with the ic number
$sql = "SELECT COUNT(*) FROM m_users WHERE icnumber = $ic ";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\\nIf this error persists, please '.
'contact you@example.com.');
}
if (mysql_result($result,0,0)>0) {
error('A user already exists with your chosen IC Number.\\n'.
'Please try your own IC Number.');
}
$random = rand(1000000,9999999990);
$sql = "INSERT INTO m_users SET
icnumber = ('$ic'),
acccode = ('$random'),
actdate = curdate(),
expdate = DATE_ADD(curdate(), INTERVAL 1 month);
";
if (!mysql_query($sql))
error('A database error occurred in processing your '.
'submission.\\nIf this error persists, please '.
'contact admin@straight-a.com.my .\\n' . mysql_error());
?>
Code:
$ic = $_POST['icnumber'];
if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {
//$ic is valid
error ('IC Number is not in right format.\\n'.
'Please enter IC Number agian.');
}
Comment