gpt4 book ai didi

PHP 表单到数据库 - 不工作

转载 作者:行者123 更新时间:2023-11-28 23:53:43 25 4
gpt4 key购买 nike

再一次,我有一个要提交到我的数据库的表单,但它不起作用,我真的不知道为什么。我测试了所有内容,但在我的代码中看不到任何错误。

这是我的表单代码:

<!-- Begin # Registration Form -->
<form method="post" action="register_teacher.php" id="registration-teacher-form" class="form-horizontal">
<div class="col-sm-12">
<p>Willkommen zu unserer <strong>Online - Essensreservierung</strong> für Lehrer. Bitte geben Sie im nachfolgenden Schritt Ihre Daten bekannt. Die Wahl des Menüs, sowie die Essenstage, können Sie im nächsten Schritt angeben.</p><br>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Schule:</label>
<div class="col-sm-10">
<select class="form-control" name="schul" id="schul">
<option value="no_selected" checked>Bitte auswählen</option>
<option value="AHS Waldschule 1">AHS Waldschule 1</option>
<option value="AHS Waldschule 2">AHS Waldschule 2</option>
<option value="AHS Waldschule 3">AHS Waldschule 3</option>
</select>
</div>
</div>
<hr>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="emai" id="inputEmail" placeholder="Ihre E-Mail Adresse">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Passwort:</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="passwor" id="inputPassword" placeholder="Ihr Passwort">
</div>
</div>
<hr>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Anrede:</label>
<div class="col-sm-10">
<select class="form-control" name="anred">
<option value="Herr">Herr</option>
<option value="Herr">Frau</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="vornam" id="inputVorname" placeholder="Ihr Vorname">
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nachnam" id="inputNachname" placeholder="Ihr Nachname">
</div>
</div>
<div class="form-group">
<label for="inputStrasse" class="col-sm-2 control-label">Strasse:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="strass" id="inputStrasse" placeholder="Ihre Adresse">
</div>
</div>
<div class="form-group">
<label for="inputPLZ" class="col-sm-2 control-label">PLZ:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="pl" id="inputPLZ" placeholder="Ihre Postleitzahl">
</div>
</div>
<div class="form-group">
<label for="inputOrt" class="col-sm-2 control-label">Ort:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="or" id="inputOrt" placeholder="Ihr Wohnort">
</div>
</div>
<div class="form-group">
<label for="inputTelefon" class="col-sm-2 control-label">Telefon:</label>
<div class="col-sm-10">
<input type="tel" class="form-control" name="telefo" id="inputTelefon" placeholder="Ihre Telefonnummer">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<p>Nachdem Sie die Registrierung abgesendet haben, erhalten Sie eine E-Mail mit einem Bestätigungslink. Sobald Sie Ihre E-Mail Adresse bestätigt haben, folgen Sie dem Link in der E-Mail um die Menüanmeldung durchführen zu können.
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submit1" value="submit" class="btn btn-custom pull-right">Send</button>
</div>
</div>
</form>
<!-- End # Registration Form -->

这是我的 register_teacher.php 的代码:

    <?php
// Create connection credentials
$db_host = 'localhost';
$db_name = 'DBNAME';
$db_user = 'DBUSER';
$db_pass = 'DBPASS';

// Create mysqli object
$connection = new mysqli ($db_host, $db_user, $db_pass, $db_name);

// Error Handler
if ($connection->connect_error) {
printf ("Connection failed: %s\n", $connection->connect_error);
exit();
}
?>

<?php


// Check if form is submitted
if (isset ($_POST['submit1'])) {
$schul = mysqli_real_escape_string ($connection, $_POST['schul']);
$emai = mysqli_real_escape_string ($connection, $_POST['emai']);
$passwor = mysqli_real_escape_string ($connection, $_POST['passwor']);
$anred = mysqli_real_escape_string ($connection, $_POST['anred']);
$vornam = mysqli_real_escape_string ($connection, $_POST['vornam']);
$nachnam = mysqli_real_escape_string ($connection, $_POST['nachnam']);
$strass = mysqli_real_escape_string ($connection, $_POST['strass']);
$pl = mysqli_real_escape_string ($connection, $_POST['pl']);
$or = mysqli_real_escape_string ($connection, $_POST['or']);
$telefo = mysqli_real_escape_string ($connection, $_POST['telefo']);




// Validate Input

$sql="INSERT INTO `teacher` (`schule`, `email`, `password`, `anrede`, `firstname`, `lastname`, `street`, `plz`, `city`, `phonenumber`)
VALUES ('$schul', '$emai', '$passwor' '$anred', '$vornam', '$nachnam', '$strass', '$pl', '$or', '$telefo')";



$query1 = mysqli_query($connection, $sql );
if(!mysqli_query($connection, $query1) ) {
exit( header("Location: /teachercp/index.php") );
}


}
?>

MySQL 连接正常。我也没有收到任何错误消息。每次单击“注册”时,我都会转到 register_teacher.php 上的空白页面!无法重定向到 teachercp/index.php,我的数据库中没有数据。

有什么建议吗?

谢谢,克里斯

最佳答案

我在本地服务器上测试了你的代码。它显示此错误:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\xampp\htdocs\111\register_teacher.php on line 39

我在你的代码中得到的错误是:

您在第 39 行漏掉了一个逗号。在您漏掉的地方查看我的图片。 enter image description here

关于PHP 表单到数据库 - 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32154130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com