Данные формы не вставляются в базу данных

Когда я отправляю свои данные из формы, они не будут вставляться в базу данных. Соединение с базой данных установлено, и когда я проверяю соединение, оно всегда отвечает, что оно подключено. База данных правильно настроена со всеми значениями: идентификатор, имя, дата, адрес электронной почты и текст. Имя пользователя, пароль и имя базы данных верны.

Синтаксис должен быть правильным. Я работаю с MySQL верстаком.

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title></title>
</head>
<body>

<link rel="stylesheet" type="text/css" href="input.css">

<header>
<h1></h1>
</header>

<nav>

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>

<main>
<form method="post" action="input.php">
<label>Name</label>
<input placeholder="Name" name="name" type="text"><br>

<label>Mailadress</label>
<input placeholder="Emailadress" name="eMail" type="email"><br>

<label>Your comment</label>
<textarea name="comment" placeholder="Text" name="comment"cols="60" rows="15"></textarea>

<input value="Send" type="submit">
</form>
</main>
</body>
</html>

Код PHP:

<?php
if($con->connect_error)
{
die("No connection" .$con-> connect_error);
}
echo "Connected";


$guestbook = new GuestbookAccess();

if (isset($_POST['submit'])){
$name = $_POST['name']; $eMail = $_POST['eMail']; $comment = $_POST['comment'];
}

class GuestbookAccess
{
private $db;

/**
* Opens the database.
*/
public function __construct()
{
$username = "tipuser";
$password = "TIP2018_WebEngineering";
$database = "tip";

// Open the database
$this->db = mysqli_connect("localhost", $username, $password);
if ($this->db == false) {
die("Unable to connect to database");
}

// Select database
mysqli_select_db($this->db, $database);
}

/**
* Evaluates current time and adds a new guestbook entry with given name,
* e-Mail and comment.
* @param String $name    User name
* @param String $eMail   User e-mail address
* @param String $comment The entry text
* @return On success: Integer Index generated by the database for the entry
*         On failure: Boolean false
*/
public function addEntry($name, $eMail, $comment)
{
// For security: suppress SQL injection
$name    = mysqli_real_escape_string($this->db, $name);
$eMail   = mysqli_real_escape_string($this->db, $eMail);
$comment = mysqli_real_escape_string($this->db, $comment);

// Add entry to the database
$result = mysqli_query($this->db, "INSERT INTO guestbook (name, email, comment) VALUES ('$name', '$eMail', '$comment')");

if ($result)
{
$result = mysqli_insert_id($this->db);
}

return $result;
}

/**
* Return in an table (two-dimensional array) all entries of the guest book.
* Each row of the table represents one entry in the guest book.
* @return table[...]["Index"]   --> Integer: Index of the entry (for deleting)
*         table[...]["Name"]    --> String: name of the user
*         table[...]["eMail"]   --> String: e-Mail of the user
*         table[...]["Comment"] --> String: The guest book entry (as text)
*         table[...]["Date"]    --> String: Date and time of the entry
*/

public function getEntries()
{
// Create query
$result = mysqli_query($this->db, "SELECT * FROM guestbook");

$table = false;
$i = 0;
while ($row = mysqli_fetch_array($result)) {
$table[$i]["Index"]   = $row["indes"];
$table[$i]["Date"]    = $row["date"];
$table[$i]["Name"]    = $row["name"];
$table[$i]["eMail"]   = $row["email"];
$table[$i]["Comment"] = $row["comment"];
$i++;
}

mysqli_free_result($result);

return $table;

// Get all entries in the guestbook
$table = $guestbook->getEntries();

if ($table) { // Check if there are enrtries
echo "\nThe guestbook contains:\n";
foreach ($table as $row) {
// Output each element
$index = $row["Index"];
$name = $row["Name"];
$date = $row["Date"];
$email = $row["eMail"];
$comment = $row["Comment"];

echo "Index: $index, ";
echo "Name: $name, ";
echo "Date: $date, ";
echo "eMail: $email, ";
echo "Comment: $comment\n";
}
}
else {
echo "\nGuest book is empty\n";

}


/**
* Closes the database.
*/
function __destruct()
{
mysqli_close($this->db);
}

}


}
?>

0

Решение

Вы должны добавить имя как submit для отправки введите в свой входной тег, чтобы сделать isset($_POST['submit']) работа в php

<input value="Send" type="submit" name="submit">
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector