0

I have a form where users can submit their contact information (first_name, last_name, email, phone, website, comment, hosting) to a database. The form was working correctly until I tried changing the 'comment' name to 'description' in the HTML. Now when I submit the form I the php echos out the response (thus leading me to think it's submitting correctly), but when I look at the table in phpMYAdmin it's empty.

The database structure is astyle_lefteyebrow > Contact

Table Structure:

CustomerID (Primary) int(11)             
FirstName   text             
LastName    text             
Email       varchar  (128)           
Phone       varchar  (20)   NULL         
Website     varchar  (500)  NULL         
Description varchar  (2000)          
Hosting     tinyint  (1)

PHP File:

<?php

$servername = "localhost";
$username = "astyle_quiggly";
$password = "**********";
$dbname = "astyle_lefteyebrow";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Check that posts have values
echo $_POST['first_name'];
echo $_POST['last_name'];
echo $_POST['email'];
echo $_POST['phone'];
echo $_POST['website'];
echo $_POST['comment'];
echo $_POST['hosting'];

// prepare and bind
$stmt = $conn->prepare("INSERT INTO Contact (FirstName, LastName, Email, Phone, Website, Description, Hosting) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssi", $firstname, $lastname, $email, $phone, $website, $description, $hosting);


// set parameters and execute
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website =  $_POST['website'];
$description = $_Post['comment'];
if ($_POST['hosting'] == 'yes') {
$hosting = 1;}
else {
$hosting = 0;
}
$stmt->execute();


$stmt->close();
$conn->close();
?>

I'm not sure why it would be working and then all the sudden stop unless it had to something to do with an encoding error. Any ideas?

strasbal
  • 143
  • 1
  • 11
  • Why do you assume your query executes successfully (`$stmt->execute();`)? It returns a boolean for a reason. – Xorifelse Nov 23 '16 at 00:49

1 Answers1

1

It should be:

$description = $_POST['comment'];

And not:

$description = $_Post['comment'];

Functions are case insensitive, but variables aren't.

Irvin
  • 830
  • 5
  • 13