Tristan Krishindat
Tristan Krishindat

Reputation: 53

Sending Email with MYSQL data

This is for a school project creating a parking reservation. The data inserts into the database fine and the email gets sent. I am just having a hard time displaying the reservation information in the email or will it be better to display the information using the variables? The goal is to have the user see the information that gets inserted to the database in the email they receive.

<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Reservation"; // Table name
$confirm_code=substr(number_format(time() * rand(),0,'',''),0,10);

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$gname=$_POST['garage'];
$license=$_POST['license'];
$myusername=$_POST['email'];
$floor=$_POST['floor'];
$spot=$_POST['spot'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(Confirmation, Fname, Lname, Gname, License, Floor, Spot )
VALUES('$confirm_code', '$fname', '$lname', '$gname', '$license', '$floor', '$spot')";
$result=mysql_query($sql);


// if suceesfully inserted data into database, send confirmation link to email 

      if($result){
// ---------------- SEND MAIL FORM ----------------

      // send e-mail to ...

      $to=$myusername;

    // Your subject

      $subject="Your Parking Reservation is Confirmed";

    // From

      $header="from: Luxury Parking <luxuryparking.comeze.com>";

    // Your message

      $message=" \r\n";

      $message.="The following is your reservation information. \r\n";

      $message.=$result;

      // send email

      $sentmail = mail($to,$subject,$message,$header);
    }

      // if not found 

      else {

      echo "Not found your email in our database";

      }

      // if your email succesfully sent

      if($sentmail){

    header("Location: reservationmade.php");

      }

      else {

      echo "Cannot send Confirmation link to your e-mail address";

      }
    ?>

Upvotes: 0

Views: 4692

Answers (1)

Goku Nymbus
Goku Nymbus

Reputation: 581

After your query is finished MySql is returning a boolean value in $result.

You need to just manually add all your values into your email with a cognitive statement.

Example:

$message .= $fname;
$message .= $lname;
$message .= $gname;
$message .= $license;
$message .= $myusername;
$message .= $floor;
$message .= $spot;

Instead of

$message .= $result;

It most likely is just putting 1 or 0 into the email.

Upvotes: 2

Related Questions