0

I've successfully created a multi page php form that uploads all the data to a mysql database. Now I'm trying to get this mail function to work with it, so we can get an email each time someone successfully completes the form. I'm getting the email now but not the information from the form. I'm not sure what I'm doing wrong, I'm guessing it's something to do with SESSION but I'm having a hard time actually finding a solution.

Here's the code I'm working with:

<?php
session_start();

foreach ($_POST as $key => $value) {
    $_SESSION['post'][$key] = $value;
} 

extract($_SESSION['post']); // Function to extract array
$connection = mysql_connect("mysql.database.com", "r-----a", "An-----1!");
$db = mysql_select_db("---------", $connection); // Storing values in database.
$query = mysql_query("insert into detail (whenadded,yourname,reservationid,reservationname,property,eta,cellphone,email,signature,petcontract) values(Now(),'$yourname','$reservationid','$reservationname','$property','$eta','$cellphone','$email','$signature','$petcontract')", $connection);

/* Set e-mail recipient */
$myemail = "blahblahblah@retreatia.com";

$yourname = ($_POST['yourname']);
$reservationid = ($_POST['reservationid']);
$reservationname = ($_POST['reservationname']);
$property = ($_POST['property']);
$eta = ($_POST['eta']);
$cellphone = ($_POST['cellphone']);
$email = ($_POST['email']);
$petcontract = ($_POST['petcontract']);

/* Let's prepare the message for the e-mail */
$subject = "$yourname has checked in using Express Checkin!";

$message = "

Information of Express Checkin User:

Name: $yourname
Reservation ID: $reservationid
Name on Reservation: $reservationname
Property: $property
Cell Phone: $cellphone
Email: $email
ETA: $eta
Pet Contract: $petcontract

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

if ($query) {
    echo '<div class="absolutecenter boxshadows"><img src="../img/thankyoupage.png" class="img-responsive"></div>';
} else {
    echo '<p><span>Form Submission Failed!</span></p>';
}

unset($_SESSION['post']); // Destroying session

?>

Also the form is populating all fields in the database successfully and produces the img file from the echo...

Littm
  • 4,923
  • 4
  • 30
  • 38
  • 1
    i don't understand how your insert is working. your variables aren't populated when you create it. – Rooster Dec 17 '14 at 20:42
  • `extract()` is what populates his variables. – mopo922 Dec 17 '14 at 20:45
  • @mopo922 ahh. wasn't familiar with that function. +1 to your answer :) – Rooster Dec 17 '14 at 20:48
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). – Jay Blanchard Dec 17 '14 at 20:49
  • Will do Jay. Thanks for the information. – ColoradoWebPro Dec 17 '14 at 20:56

1 Answers1

3

Since you did this:

extract($_SESSION['post']); // Function to extract array.

... this block is unnecessary:

$yourname = ($_POST['yourname']);
$reservationid = ($_POST['reservationid']);
$reservationname = ($_POST['reservationname']);
$property = ($_POST['property']);
$eta = ($_POST['eta']);
$cellphone = ($_POST['cellphone']);
$email = ($_POST['email']);
$petcontract = ($_POST['petcontract']);

In fact, it's probably why your variables aren't populating. They're getting overwritten with empty values since $_POST doesn't contain values from previous pages.

mopo922
  • 6,293
  • 3
  • 28
  • 31