Luodeni Posted March 11, 2009 Share Posted March 11, 2009 I made a function to check whether the first/middle/and lastname already exists in my database. It works just fine for latin names but it does not work on Chinese for example. My database has the value stored as unicode aswell and the characters represent the same I used (星星张 (xingxing Zhang)) as a name to check. Strangely enough it says this one doesn't exist yet, although it does. did anyone ever encountered this problem? here is the function <?php function checkDuplicateContact( $firstName, $middleName, $lastName ) { $SQL = "SELECT customerid, firstname, middlename, lastname FROM tb_contacts WHERE firstname = '$firstName' AND middlename = '$middleName' AND lastname = '$lastName' "; $res = mysql_query( $SQL ); if ( mysql_num_rows( $res ) == 1) { $error = "<div style='color: #D00;'>" . $_POST['firstname'] . " " . $_POST['middlename'] . " " . $_POST['lastname'] . ", already exists!</div>"; } elseif ( mysql_num_rows( $res ) == 0 ) { require 'includes/dbConnect.php'; mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET NAMES 'utf8'"); $SQLAdd = "INSERT INTO tb_contacts ( firstname, middlename, lastname, age, gender, dateofbirth, married, children, nationality, religion, companyid, jobtitle, jobdescription, officephone, homephone, mobilephone, mobilephone2, email, email2, instantmessenger, instantmessenger2, fax, hobbies, favouritefood, favouritebeverage, miscelleneous, createdby, createddate ) VALUES ( '$firstName', '$middleName', '$lastName', '$age', '$gender', '$dateofBirthFull', '$martialState', '$children', '$nationality', '$religion', '$companyId', '$jobTitle', '$otherJobInfo', '$officePhone', '$housePhone', '$mobilePhone', '$mobilePhone2', '$email', '$email2', '$instantMessenger', '$instantMessenger2', '$fax', '$hobbies', '$favouriteFood', '$favouriteBeverage', '$miscelleneous', '$createdBy', CURRENT_TIMESTAMP() ) "; $resAdd = mysql_query( $SQLAdd ); mysql_close(); $error = "<div style='color: #48830b'>" . $_POST['firstname'] . " " . $_POST['middlename'] . " " . $_POST['lastname'] . ", added to the database</div>"; $_POST = ""; } else { $error = "<div style='color: #D00;'>" . mysql_error() . "Please contact the webadmin</div>"; } return $error; } ?> <?php if ( isset( $_POST['firstname'] ) && $message != "") { echo "<div style='color: #D00;'>" . $message . "</div><br />\n"; } elseif ( isset( $_POST['firstname'] ) && empty( $message) ) { echo checkDuplicateContact( $firstName, $middleName, $lastName ); } ?> Link to comment https://forums.phpfreaks.com/topic/148900-checking-unicode-values-with-mysql_num_rows/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.