Jun 8, 2012

Quick workaround for Moodle registration name

Moodle is a good web application where educators can use it to manage course effectively. It allows educators to conduct fully online courses where Moodle provide richly features such as forums, database, wikis, assignments, and quizzes.

For more information, please visit

As for me, I've been playing around with Moodle for 2-3 months just to know the system and how I can use it as a learning management system. So far, all the features and functionality of Moodle satisfied my requirement to create an online exam system for student. What bother me a bit is, when student register their account, some of them use small capital and other use big capital for their details, and Moodle store the details without standardize the user registration entries. (e.g Firstname: Azizul azim, Lastname: AMRI instead of Firstname: Azizul Azim, Lastname: Amri)

So, I made a quick adjustment (literally) to solve the problem temporarily.

$host="localhost"; // Host name
$username="mysql_username"; // Mysql username
$password="mysql_password"; // Mysql password
$db_name="moodle_database"; // Database name

$tbl_name=mdl_user; // Table name

//Connect to server and select databse.
$connection = mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

// retrieve all fields from $tbl_name
$sql="SELECT * FROM $tbl_name";

if(!$result) {
        die("Database table Selection Failed: " . mysql_error());

while ($row = mysql_fetch_array($result)) {
        echo($row['firstname'] . " " . $row['lastname'] . " (" . ucwords(strtolower($row['firstname'])) . " " .  ucwords(strtolower($row['lastname'])) . ") " . $row['city'] . " (" .  ucwords(strtolower($row['city'])) . ")\n");

        $firstname = ucwords(strtolower($row['firstname']));
        mysql_query("UPDATE " . $tbl_name . " SET firstname='" . $firstname . "' WHERE id=" . $row['id']);

        $lastname = ucwords(strtolower($row['lastname']));
        mysql_query("UPDATE " . $tbl_name . " SET lastname='" . $lastname . "' WHERE id=" . $row['id']);

        $city = ucwords(strtolower($row['city']));
        mysql_query("UPDATE " . $tbl_name . " SET city='" . $city . "' WHERE id=" . $row['id']);


With this quick workaround, all the firstname, lastname, and city field will be updated to big capital on initial character and small capital on the rest of the character.