mmarif4u Posted January 4, 2007 Share Posted January 4, 2007 Hi Every body...I make this script with mysql query but it has problem..i want to enter icnumber format like belowFormat 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 is here [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 [email protected].'); } 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 [email protected] .\\n' . mysql_error()); ?>[/code]I amke this query for that to check the icnumber format but not work..[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.'); }[/code]Can any help out from this problem...Thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/32803-solved-how-to-store-correct-format-to-db-through-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.