PHP: how to properly use return statements
<p>Problem: I have a class called 'user' and a function called 'registerUser'. I want to send a successful registration to a page but an unsuccessful registration to a different page.</p>

<p>I have not filled out the return statement because that is where i am unsure if that is how i can fix the problem. I am new to php and believe that could work but as i said, i am new and still learning.</p>

<pre><code>class User {
    function registerUser($userName, $userPassword) {
    // Connect to database
    $dbLink = mysql_connect($this-&gt;dbHost, $this-&gt;dbUser, $this-&gt;dbPass);
    if(!$dbLink) die("Could not connect to database. " . mysql_error());

    // Select database
    mysql_select_db($this-&gt;dbName);

    // Insert data
    $query = "insert into $this-&gt;dbUserTable values (NULL, \"$userName\", \"$userPassword\")";
    $result = mysql_query($query);

    // Test to make sure query worked
    if(!$result) {
        return(false);
    }

    // Get the user ID
    $this-&gt;userID = mysql_insert_id();

    // Close database connection
    mysql_close($dbLink);

    // Assign the values to the data members
    $this-&gt;userName = $userName;
    $this-&gt;userPassword = $userPassword;
    return(true);
} // End registerUser()
}
</code></pre>

<p>My php code that calls this class is simple.</p>

<pre><code>    &lt;?
// processRegister.php
//////////////////////

// First include the class definition
include('UserClass.php');

// Next, create an instance of the class
$newUser = new User;

// Call the registerUser() method, passing in the required variables
if ($newUser-&gt;registerUser($userName, $userPassword)) {
  header('Location: www.google.com');
} 
else {
  header('Location: www.yahoo.com.com');
}
?&gt;
</code></pre>

<p>any help is much appreciated!</p>
