我试图进行调查问卷,但它只是没有连接我的数据库,这很奇怪,因为在其他php几乎相同的连接工作。你能帮忙吗?
<?php
if (isset($_POST['pohlavi'])) {
if (!isset($_POST['platforma']) || !isset($_POST['ano']) || !isset($_POST['nazor']) || $_POST['platforma'] = "" || $_POST['nazor'] = "" || $_POST['ano'] = "") {
die("Nastala chyba, musíte vyplnit všechny pole! Dotazník nebyl odeslán.");
} else {
$conn = new mysqli('localhost', 'adress', 'password', 'czseznamka');
$conn->query("INSERT INTO dotaznik (pohlavi, platforma, ano, nazor) VALUES ('" . $_POST['pohlavi'] . "', '" . $_POST['platforma'] . "', '" . $_POST['ano'] . "' , '" . $_POST['nazor'] . "');");
echo '<span style="text-align:center;color:green;font-size:30px;"> Dotazník odeslán</span>';
}
}
?>
答案 0 :(得分:0)
尝试使用以下启用错误
if (isset($_POST['pohlavi'])) {
if (!isset($_POST['platforma']) || !isset($_POST['ano']) || !isset($_POST['nazor']) || $_POST['platforma'] = "" || $_POST['nazor'] = "" || $_POST['ano'] = "") {
mysqli_report(MYSQLI_REPORT_STRICT);
try {
$connection = new mysqli('localhost', 'root', '', 'dbname') ;
$connection->query("INSERT INTO dotaznik (pohlavi, platforma, ano, nazor) VALUES ('" . $_POST['pohlavi'] . "', '" . $_POST['platforma'] . "', '" . $_POST['ano'] . "' , '" . $_POST['nazor'] . "');");
} catch (Exception $e ) {
echo "Service unavailable";
echo "message: " . $e->message;
exit;
}
}
}