Specifications

FIGURE 24.5
Registration was successfulthe user can now go to the members page.
The register() function is in the included library called user_auth_fns.php. This function is
shown in Listing 24.9.
Listing 24.9 register() Function from user_auth_fns.phpThis Function Attempts to Put
the New Users Information in the Database
function register($username, $email, $password)
// register new person with db
// return true or error message
{
// connect to db
$conn = db_connect();
if (!$conn)
return “Could not connect to database server - please try later.”;
// check if username is unique
$result = mysql_query(“select * from user where username=’$username’”);
if (!$result)
return “Could not execute query”;
if (mysql_num_rows($result)>0)
return “That username is taken - go back and choose another one.”;
// if ok, put in db
Building Practical PHP and MySQL Projects
P
ART V
512
30 7842 ch24 3/6/01 3:34 PM Page 512