Introduction:

 To go with signup.php I will continue introducing you how to write code for checkup.php file which  is used to look up the username in the database and returns a string indicating whether it has been already been taken.

checkup.php

<?php 
  require_once 'functions.php';

  if (isset($_POST['user']))
  {
    $user   = sanitizeString($_POST['user']);
    $result = queryMysql("SELECT * FROM members WHERE user='$user'");

    if ($result->num_rows)
      echo  "<span class='taken'>&nbsp;&#x2718; " .
            "This username is taken</span>";
    else
      echo "<span class='available'>&nbsp;&#x2714; " .
           "This username is available</span>";
  }
?>

  As we can see, it relies on the functions sanitizeString and queryMysql. Therefore, the program first includes the file functions.php.

 Then, if the $_POST variable user has a value, the function looks it up in the database and, depending on whether it exists as a username, outputs either “This username is taken” or “This username is available.” Just checking the function mysql_num_rows against the result is sufficient for this, as it will return  0  for not found, or 1 if it is found.

 The HTML entities &#x2718; and &#x2714; are also used to preface the string with either a cross or a checkmark. Below is an example new user creates an account which is already existed in the database.

Duplicated account error window

Fig. 1. Duplicated account error.

 Conclusion:

  In this section I helped you to write code for checkup.php file combined with signup.php file to do checking and creating a new user account for the site. I hope that you can find useful information in this section.

GET A QUOTE
close slider

    BusinessE-commerce/ Online storeNon-profitPersonal websiteI'm not sureOther

    Create a new websiteOverhaul of my websiteMinor changes to my websiteOther

    Help customer find my business onlineSell my product or service and take payments onlineSell my product or service, taking payments offlineProvide information to the publicOther

    ASAPIn the next few weeksIn the next monthIn the next 2-3 monthsI'm not sureOther

    I'm not sureLess than 1 monthUp to 3 monthsUp to 6 monthsOther

    Pin It on Pinterest