mmarif4u Posted January 3, 2007 Share Posted January 3, 2007 Hi Every body[b]Happy New year.....[/b]I want that mysql check the value of icnumber thata user want to insert to database..For example icnumber format is (az123-654-00125s)1st query check this format bcoz everybody has thisformat type ic issued by gov.code are...[code] $dbcnx = dbConnect('db'); $required_fields = array( 'icnumber','acccode','username', 'fullname', 'email', 'hp');foreach ($required_fields as $field) { if (!isset($_POST[$field]) || empty($_POST[$field])) { error("One or more required fields were left blank. \\n Please fill them in and try again."); } else { $cleaned_for_sql[$field] = mysql_real_escape_string($_POST[$field]); }}//$sql = "SELECT COUNT(*) FROM m_users WHERE username = '" . $cleaned_for_sql['username'] . "'";//$sql_result = mysql_query($sql);//if (mysql_result($sql_result, 0) > 0) { // error("That username is already in use.\\n Please choose another.");//}$password = substr(md5(time()),0,6); $sql = "UPDATE `m_users` SET ";$sql .= "`password` = PASSWORD('" . $password . "'), ";$sql .= "`email` = '" . $cleaned_for_sql['email'] . "', ";$sql .= "`hp` = '" . $cleaned_for_sql['hp'] . "', ";$sql .= "`username` = '" . $cleaned_for_sql['username'] . "', ";$sql .= "`fullname` = '" . $cleaned_for_sql['fullname'] . "' ";$sql .= "WHERE `icnumber` = '" . $cleaned_for_sql['icnumber'] . "' ";$sql .= "AND `acccode` = '" . $cleaned_for_sql['acccode'] . "' ";$sql_result = mysql_query($sql) or error("Error executing query [$sql]: " . mysql_error()); if (mysql_affected_rows($dbcnx) == 0) { error("Your IC number and Access Code do not match to database data. \\n Please try again.");}[/code]thanks inadvance Link to comment https://forums.phpfreaks.com/topic/32660-how-to-check-these-values-against-mysql/ Share on other sites More sharing options...
matto Posted January 3, 2007 Share Posted January 3, 2007 You may want to consider using regular expressions to valid the number that is inputted by the user[url=http://nz2.php.net/manual/en/function.ereg.php]http://nz2.php.net/manual/en/function.ereg.php[/url] Link to comment https://forums.phpfreaks.com/topic/32660-how-to-check-these-values-against-mysql/#findComment-152089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.