如何从表中选择数据并使其成为字符串?

I am trying to use a database where the email can have multiple entries, but i would like to prevent duplicate entries. Currently i have:

    <?php
    "SELECT Notes, itemName from UserItems where email = '$email'";
    if("itemName" == $name && "Notes" == $desc) {
        echo "duplicate";
    }
    ?>

But itemName and Notes need to become strings for my if statement to work

My insert function is lower in my code but ill post it

    $insert = ("insert into UserItems (itemName, ItemNumber, email, Price, Notes) Value (\"$name\", \"$ItemNumber\", \"$email\", \"$price\", \"$desc\")");

Am I missing something here? I held off answering cause I thought this would be too obvious and my post would waste time -

<?php
// add actual db connection info here
$email = 'someon@somewhere.com';
$name = 'John';
$desc = 'Some Description';
$row = mysql_fetch_array(mysql_query("SELECT Notes, itemName from UserItems where email = '$email'"));
if($row['itemName'] == $name && $row['Notes'] == $desc) {
    echo "duplicate";
}
?>

You never actually run a query or fetch the results. Or define the variables you're comparing against. Are they $_POST, $_GET, results of the last row or something?

What about counting the number of entries where email = '$email'?

Based off the conversation we had in the comments, it sounds like your best bet is to handle this functionality at the database layer, by adding a unique contraint across all three columns (email, itemName, notes). With this solution the database will not allow more than one row with the same value for all three columns.

The mysql command would be:

alter table <your_table> add unique (`email`, `itemName`, `notes`);

// Will be inserted/updated no problem
foo@bar.com, itemName1, notes1
foo@bar.com, itemName1, notes2
foo@bar.com, itemName2, notes1

// An error will be returned because this row already exists
foo@bar.com, itemName1, notes2

The only drawback is that writes to the database will more costly as all three columns (notes especially) will have to be considered for the unique constraint.

Your other option is to load all rows matching the email address, then step through each row searching for matches against itemname and notes, which will be even more painful.