Updation logic to remove redundancy
<p>I am using PHP to update my table...For particulars I am confused with the logic. Actually I want to remove redundancy from my DB. Suppose I have table having values <code>'apple','banana', orange</code>. During insertion time I have added condition if that particular fruit name is available than give error. But during updation time if I give similar logic then though it remove redundancy but if I I wish to edit other information other then name, it won't allow me to do that. Although It going well if I use third name other than all like 'grapes'. How can I modidy this logic. My code is.</p>

<pre><code>if ( $name != "" ) {
    $query = mysql_query( "SELECT name FROM album WHERE name='" . $name . "'" );
    if ( mysql_num_rows( $query ) != 0 )
         $error = "Record Not Saved. Name already Exist!";
}
</code></pre>

<p><strong>NOTE</strong> My code is regarding name of Album while I have chooses example of name of fruits to define problem.</p>

<p>I modify to clearify better that...</p>

<ul>
<li>SELECT if exists</li>
<li>If exists
<ul>
<li>Update</li>
</ul></li>
<li>Else
<ul>
<li>Update </li>
</ul></li>
</ul>

<p>AS I want my fruit name to be unique. So during time of updation if <code>apple</code> exist than it update rest information about name=<code>apple</code> if not exist than also it update all information about <code>apple</code> including its name (my where condition includes some other variable). </p>
