Jump to content

Update Table And Send Email


Ampboy

Recommended Posts

I have something that I cannot get to work.. The code I usually use uses INSERT and not UPDATE and has the user fill out all the fields. What I have now is a form where the user updates their PIN and email address. I have the update working. I just need to figure out how to get an email to the admin and to the end user based on where they are located  Here is what I have:

$dbhost 	= "localhost";
$dbname		= "jimkoons_freshstart";
$dbuser		= "jimkoons_start";
$dbpass		= "Koons123";

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

$sql = "Update Customers SET Email = :Email WHERE PIN = :PIN";                                      
$stmt = $conn->prepare($sql);              
$stmt->bindValue(':PIN', $_POST['PIN'], PDO::PARAM_STR);      
$stmt->bindValue(':Email', $_POST['Email'], PDO::PARAM_STR);


                header("Location: http://koonsfreshstart.com/thank-you");
              
$stmt->execute(); 

Here is the snippet I use to email based on location in previous applications

$STH->bindValue(':PIN', $_POST['PIN']); 
$STH->bindValue(':FirstName', $_POST['First']); 
$STH->bindValue(':LastName', $_POST['Last']);
$STH->bindValue(':Email', $_POST['Email']);


try {  
// Retrieve the user's name and associated list items
    $sql = "SELECT *
            FROM Customers
            WHERE PIN = PIN";

    $stmt = $conn->prepare($sql); // Prepare the statement
    if($stmt->execute(array($_POST['PIN'])))
    {

        // Loop through the returned results
        while($row = $stmt->fetch()) {

            // Save the Store name
            $PIN = $row['PIN'];

            // Create an array of items
            $items[] = $row['PIN'];
        }

        $stmt->closeCursor(); // Free memory used in this query
        
    		$first = $_POST["first"];
                $last = $_POST["last"];
               $email = $_POST["email"];
   
$PIN = $_POST['PIN'];
        switch ($PIN)
        {
 case "East":
             	
      
      

$to = "mail@mail.com";
$subject = "Mail";

$message = "$first $last
Email Address: $email";
$user = "$email";
$usersubject = "Thank You for your submission";
$userheaders = "From: no-reply@mail.com\n";

$usermessage = "Thank you for submitting your information.  We will be contacting you soon with more information on a customized extended service agreement for your vehicle.  We look forward to working with you!";

mail($to,$subject,$message,$headers);

mail($user,$usersubject,$usermessage,$userheaders);
                header("Location: http://mail.com/second/");
                break;
 
 etc...

Any help on making this work would be appreciated.. It is showing any errors, but it is not redirecting or emailing any of the data.

 

Thanks for your help!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.