Q: PHP/MySQL query deleting data but not re-inserting I have this PHP Code:
$stmt = $pdo_conn->prepare("DELETE from tickets_extra_emails where ticketnumber = :ticketnumber ");
    $stmt->execute(array(':ticketnumber' => $ticket["ticketnumber"]));
    $cc_contact_line = '';
    foreach(explode("\n", $_POST["cc_contacts"]) as $cc_contact_line) {
        //then insert new if its not blank
        if(filter_var($cc_contact_line, FILTER_VALIDATE_EMAIL)) {
            //see if it currently exists
            $stmt = $pdo_conn->prepare("SELECT * from tickets_extra_emails where ticketnumber = :ticketnumber and email_address = :email_address ");
            $stmt->execute(array(':ticketnumber' => $ticket["ticketnumber"], ':email_address' => $cc_contact_line));
            $records = $stmt->fetchAll(PDO::FETCH_ASSOC);
            if(count($records) == 0) {
                echo 'insert '.$ticket["ticketnumber"].' - '.$cc_contact_line.'<br>';
                $stmt = $pdo_conn->prepare("INSERT into tickets_extra_emails (ticketnumber, email_address) values (:ticketnumber, :email_address) ");
                $stmt->execute(array(':ticketnumber' => $ticket["ticketnumber"], ':email_address' => $cc_contact_line));
            }
        }
    }

that makes each line of a textarea a variable in a foreach loop.
if i put lines in the textarea and submit the form, it saves the data but then if there is already data in and i submit the form, it removes it.
what do i have wrong in my code? I have commented everything it does

A: Theres a significant difference between MySQL INSERT and UPDATE.
You will need to check against the database where you are inserting to and use a query to check if there is data existing in that row. Based on that query you can restructure your insert statement to be conditional and switch from an INSERT to an UPDATE. 
Deleting existing data will not allow you to re-insert into the rows, the rows are existing and therefor require UPDATE. However if you are removing whole rows then you can indeed re insert the rows. I see this as not entirely efficient, when you can utilize the efficiency of UPDATE to its benefit here.

A: AFAIK, fetchAll will fail if there are 0 rows, so you won't be able to run a count on the records.  Do you have errors enabled or logged?
I see what you are trying to do and why you want to delete then reinsert, although maybe not the best approach.  
Update:  Apparently rowCount() shouldn't be relied on for selects, so I think the best alternative is to change your select query to select a count.  This will always return a value as long as the query is valid so you shouldn't have to worry about the fetch failing.  As you noticed below, I just changed the SELECT * to a SELECT count(*) so this will count how many rows match your constraints.  Then use fetchColumn() to select the first column of the first row (the count).
$stmt = $pdo_conn->prepare("SELECT count(*) from tickets_extra_emails where ticketnumber = :ticketnumber and email_address = :email_address ");
$stmt->execute(array(':ticketnumber' => $ticket["ticketnumber"], ':email_address' => $cc_contact_line));
$records = $stmt->fetchColumn();

