title: I don't know what's wrong with my code. I'm a newbie. The prob is - Notice: Undefined variable: result
body: <p>When I save info. I works fine. No errors and databse is saved. But when I enter something in database which already exists like firstname(to check if uniqueness works). It gives the following NOTICE and also echo the message - "Username taken." . I made many changes but no results, Thanks in adcance</p>
  
  <pre><code>&lt;?php
  
  require_once('includes/database.php');
  require_once('includes/user.php');
  require_once('includes/functions.php');
  require_once('includes/session.php');
  
  ?&gt;
  
  &lt;?php
  
  if(isset($_POST['submit'])){ //Form submitted
  
  
   $username  = $database-&gt;escape_value($_POST['vnumber']);
  $firstname = $database-&gt;escape_value($_POST['fname']);
  $lastname  = $database-&gt;escape_value($_POST['lname']);
  $email     = $database-&gt;escape_value($_POST['email']);
  $password  = $database-&gt;escape_value($_POST['password']);
  $password  = md5($password);
  </code></pre>
  
  <p>//Check fields aren't empty</p>
  
  <pre><code>if (empty($username)){
  
  echo "Please fill in username";
  
  } else if (empty($firstname)){
  
  echo "Cannot be blank";   
  
  } else if(empty($lastname)){
  
  echo "Cannot be blank";    
  
  } else if(empty($email)){
  
  echo "Cannot be blank";
  
  } else if (empty($password)){
  
  echo "Cannot be blank";
  
  } else {
  </code></pre>
  
  <p>//Checking uniqueness of username</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM user_info WHERE fname='$firstname'");
  
  $rows = mysql_num_rows($query);
  
  if ($rows == 1){
  
  echo "Username taken !";    
  
  } else {
  </code></pre>
  
  <p>//If rows = 0. Fields not empty. Data can be saved.</p>
  
  <pre><code> $result ="";
  
   global $database;
  
   $sql    = "INSERT INTO user_info (vnumber, fname, lname, email, password) VALUES 
  
     ('$username', '$firstname', '$lastname', '$email', '$password')";
  
   $result = $database-&gt;query($sql);
  }
  if($result){
         die( "Regisgtration success !");
  } else {
  
         die("Something went wrong !");
  }
  }
  
  }
  ?&gt;
  </code></pre>