简体   繁体   English

PHP-数据库中缺少条目(bind_param)

[英]PHP - missing entries in Database (bind_param)

Good morning, I try to fill up a database (with PHP and HTML) and followed a tutorial so far. 早上好,我尝试填充数据库(使用PHP和HTML),并按照教程进行学习。 After a few successful chapters I get stucked at the Point where I have to fill up the database with some data. 在成功学习了几章之后,我陷入了必须在数据库中填充一些数据的问题。
Everything seems working fine. 一切似乎都正常。 But when I save entries it only stores 3 values. 但是,当我保存条目时,它仅存储3个值。 In my example are this the columns "id" "created_at" and "text". 在我的示例中,这是列“ id”,“ created_at”和“ text”。 The other columns stays empty. 其他列保持为空。 Iam using: 我在用:

  • PHP Version 7.1.14 PHP版本7.1.14
  • Apache WebServer 2.0 (on Windows) Apache WebServer 2.0(在Windows上)
  • MSVC14 (Visual C++ 2015) MSVC14(Visual C ++ 2015)

(german) Tutorial (德语) 教程

 <?php require ('dbconnect.php'); $db = mysqli_connect (MYSQL_HOST, MYSQL_BENUTZER, MYSQL_KENNWORT, MYSQL_DATENBANK); if ($db->connect_errno) { die('Sorry'); } $db->set_charset('utf8'); if (isset($_POST['aktion']) and ($_POST['aktion']=='speichern')) { $vorname = ""; if (!isset($_POST['vorname'])) { $vorname = trim($_POST['vorname']); } $email = ""; $if (!isset($_POST['email'])) { $email = trim($_POST['email']); } $nachname = ""; if (isset($_POST['name'])) { $name = trim($_POST['name']); } $text = ""; if (isset($_POST['text'])) { $text = trim($_POST['text']); } $funktion=""; $created_at = date("Ymd H:i:s"); if ( $vorname != '' or $name != '' or $created_at != '' or $text != '') { $einfuegen = $db->prepare("INSERT INTO gaestebuch (name, email, text, vorname, funktion, created_at) VALUES (?,?,?,?,?,NOW())"); $einfuegen->bind_param('sssss', $vorname, $email, $text, $nachname, $funktion); $einfuegen->execute(); if ($einfuegen->execute()) { header('Location: config.php?aktion=feedbackgespeichert'); die(); echo "<h1>gespeichert</h1>"; } } } if (isset($_POST['aktion']) and $_POST['aktion']=='feedbackgespeichert') { echo "<p>Es liegen keine Daten vor :(</p>"; } $daten = array(); if ($erg = $db->query("SELECT * FROM gaestebuch")){ if ($erg->num_rows) { while($datensatz = $erg->fetch_object()) { $daten[] = $datensatz; } $erg->free(); } } if (!count($daten)) { echo "<p>no data :</p>"; } else { ?> <table> <thead> <tr> <th>ID</th> <th>name</th> <th>vorname</th> <th>email</th> <th>text</th> <th>funktion</th> <th>created_at</th> <th>deleted_at</th> </tr> </thead> <tbody> <?php foreach ($daten as $inhalt){ ?> <tr> <td><?php echo $inhalt->id; ?></td> <td><?php echo $inhalt->name; ?></td> <td><?php echo $inhalt->vorname; ?></td> <td><?php echo $inhalt->email; ?></td> <td><?php echo $inhalt->text; ?></td> <td><?php echo $inhalt->funktion; ?></td> <td><?php echo $inhalt->created_at; ?></td> <td><?php echo $inhalt->deleted_at; ?></td> </tr> <?php } ?> </tbody> </table> <?php } ?> <form action="" method="post"> <label>Vorname: <input type="text" name="vorname" id="vorname"> </label> <label>Nachname: <input type="text" name="name" id="name"> </label> <label>email: <input type="text" name="email" id="email"> </label> <label>text: <textarea name="text" id="text"></textarea> </label> <label>funktion: <textarea name="funktion" id="funktion"></textarea> </label> <input type="hidden" name="aktion" value="speichern"> <input type="submit" value="speichern"> </form> 

Can anyone help me? 谁能帮我? :) :)

Updated 更新

Your 2 if conditions are logically wrong: 您的2,如果条件在逻辑上是错误的:

these 这些

if (!isset($_POST['vorname'])) {
    $vorname = trim($_POST['vorname']); 
}
$email = "";
$if (!isset($_POST['email'])) {
    $email = trim($_POST['email']);
}

should be: 应该:

if (isset($_POST['vorname'])) {
    $vorname = trim($_POST['vorname']); 
}
$email = "";
$if (isset($_POST['email'])) {
    $email = trim($_POST['email']);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM