我创建了一个bootstrap表单,并希望将表单中的数据包含到我的数据库中。我的问题是它不起作用,我不明白为什么。在我看来一切都是正确的。我现在正在寻找几个小时,但我无法找到问题。
您可以在此处找到我的表单:http://schulkantine.ccsolution.at/registration.php 请不要看风格,我必须稍后再定制。
这是我的register.php!数据库连接正在运行。
<?php
// Create connection credentials
$db_host = 'localhost';
$db_name = 'DBNAME';
$db_user = 'DBUSER';
$db_pass = 'DBPASSWORD';
// Create mysqli object
$connect = new mysqli ($db_host, $db_user, $db_pass, $db_name);
// Error Handler
if ($connect->connect_error) {
printf ("Connection failed: %s\n", $connect->connect_error);
exit();
}
?>
<?php
// Check if form is submitted
if (isset ($_POST['submit'])) {
$anrede = mysqli_real_escape_string ($connect, $_POST['anrede']);
$vorname = mysqli_real_escape_string ($connect, $_POST['vorname']);
$nachname = mysqli_real_escape_string ($connect, $_POST['nachname']);
$strasse = mysqli_real_escape_string ($connect, $_POST['strasse']);
$plz = mysqli_real_escape_string ($connect, $_POST['plz']);
$ort = mysqli_real_escape_string ($connect, $_POST['ort']);
$email = mysqli_real_escape_string ($connect, $_POST['email']);
$telefon = mysqli_real_escape_string ($connect, $_POST['telefon']);
// Validate Input
$query = mysql_query("INSERT INTO user (anrede, firstname_parent, lastname_parent, street_parent, plz_parent, city_parent, email, phonenumber_parent)
VALUES ('$anrede', '$vorname', '$nachname', '$strasse', '$plz', '$ort', '$email', '$telefon')") or die(mysql_error());
}
?>
希望有人可以帮助我并告诉我我的错误是什么!
答案 0 :(得分:3)
尝试更改
INSERT INTO user (anrede, firstname_parent, lastname_parent, street_parent, plz_parent, city_parent, email, phonenumber_parent) VALUES ('$anrede', '$vorname', '$nachname', '$strasse', '$plz', '$ort', '$email', '$telefon')"
到
INSERT INTO `user` (`anrede`, `firstname_parent`, `lastname_parent`, `street_parent`, `plz_parent`, `city_parent`, `email`, `phonenumber_parent`) VALUES ('$anrede', '$vorname', '$nachname', '$strasse', '$plz', '$ort', '$email', '$telefon')"
答案 1 :(得分:1)
在registration.php文件中替换此行。你忘了添加&#34; name&#34;属性所以你的条件 if(isset($ _POST [&#39; submit&#39;]))不起作用。
<button type="submit" name="submit" value="submit" class="btn btn-custom pull-right">Send</button>