lundi 26 novembre 2018

HTML-Form to Database using PHP

I've been trying to connect this HTML-Form with my MySql-Database so I can get messages sent to me from my website. But I keep Getting this message:

"The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. "

I've tried many different things from other people who had the same problem but it didn't seem to work for me.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
        <meta content="utf-8" http-equiv="encoding">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="js/jquery.js"></script>
        <link rel="stylesheet" href='https://fonts.googleapis.com/css?family=ABeeZee'>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="js/navshrink.js"></script>
        <link rel="stylesheet" type="text/css" href="css/contact.css">
    </head>



 <div class="contactCon">
       <form class="contactForm" action="contactForm.php" method="post" enctype="application/x-www-form-urlencoded">
          <ul class="flex-container">
             <li class="flex-item">
                <ul class="flex-container2">
                    <li class="flex-item2">enter code here
                        <label for="fname">First Name:</label>
                        <input type="text" id="fname" name="firstname" placeholder="Your First Name..">
                    </li>
                    <li class="flex-item2">
                        <label for="lname">Last Name:</label>
                        <input type="text" id="lname" name="lastname" placeholder="Your Last Name..">
                    </li>
                    <li class="flex-item2">
                        <label for="email">E-mail:</label>
                        <input type="text" id="email" name="email" placeholder="Your E-mail..">
                    </li>
                </ul>
                <li class="flex-item">
                    <label id="subject-label" for="subject">Subject:</label>
                    <textarea type="text" id="subject" name="message" placeholder="Write Me Something.."></textarea>
                    <input id="submit-button" type="submit" value="Submit">
                </li>
             </li>
          </ul>
       </form>
    </div>

And here is my PHP-code for the form:

<?php
  // Create Variables for Database Information
  $host = 'xxxxxx';
  $userName = 'xxxxxxx';
  $dbPassword = 'xxxxxx';
  $dbName = 'xxxxxxxx';

  // Create Connection to the Database
  $con = mysqli_connect($host,$userName,$dbPassword,$dbName);

  // Check connection
  if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
    // Create Variables for every Input
    $firstname = mysqli_real_escape_string($con, $_POST['firstname']);
    $lastname = mysqli_real_escape_string($con, $_POST['lastname']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $message = mysqli_real_escape_string($con, $_POST['message']);



    // Insert Input into the Database
    $sql = "INSERT INTO contactMe(firstname, lastname, email, message)
      VALUES ('$firstname','$lastname','$email','$message')";

    // Check for Errors
    if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    // Close Connection
    mysqli_close($con);
?>

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire