Jump to content

Inserting a Value into SQL where the value doesnt already exist


bicky

Recommended Posts

Hello All

 

Hoping for some help this time :)

 

I have created a statement that works fine now, taking the value from a form and inserting into a MS SQL table.

 

I now want to expand the code, to only insert when the value doesnt already exist...

 

My Current Code is as follows:

 

$tsql = "INSERT INTO email_supp
        (email,date,source)
        VALUES
        (?,?,?)";

$today = date("d/m/y");
$source= 'Email Form';
$email = array($_POST['emailopt'], $today,$source);

/* Prepare and execute the query. */
$stmt = sqlsrv_query( $conn, $tsql, $email);
if( $stmt )
{
     echo "Row successfully inserted.\n";
}
else
{
     echo "Row insertion failed.\n";
     die( print_r( sqlsrv_errors(), true));
}

/* Free statement and connection resources. */
/*sqlsrv_free_stmt( $stmt);*/

sqlsrv_close( $conn);
?>

 

My main problem here is I dont really know how the value is taken from the form, I know its within this part (array($_POST['emailopt']) but If i wanted to just specify the value to a variable my PHP seems to then fall over.

 

ANY help would be appreciated..

 

Thanks in advance

 

Bicky

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.