“插入到”没有任何作用。 (sqli_error均不返回任何内容)

时间:2019-07-11 12:53:00

标签: php sql database

为了练习,我将根据狼蛛的习惯创建一个个人日志页面。我正在尝试编码“创建”按钮。当我运行此代码时,填写表格并单击按钮,什么也没有发生,并且我什么也没有。没有sqli错误或我的任何回声。有人可以帮忙吗?

我尝试删除表名,将各种变量全局化,将其取消连接,并将撇号更改为双引号。

queries.php:

<?php include "database.php"?>
<?php include "functions.php"?>
<?php
if(isset($_POST['create'])){
    create();
}    
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>QUERIES</title>
</head>
<body style="background-color: #FF8360" >
   <div class="container" style="height: 700px; width: 20%; background-color: #E8E288; float:left; padding-left: 10px; padding-right: 10px; padding-bottom: 10px; padding-top: 10px;">
       <container class="col-xs-6" style="text-color: darkgrey; font-family: verdana;">
         <form action="queries.php" method="post">
          <label for="genus">Genus</label>
          <input type="text" name="genus">
          <br>
          <label for="species">Species</label>
          <input type="text" name="species">
          <br>
          <label for ="lastFeed">Last Fed</label>
          <input type="date" name="lastFed">
          <br>
          <label for="lastMolt">Last Molt</label>
          <input type="date" name="lastMolt">
          <br>
           <label for="rehouse">Last Rehoused</label>
          <input type="date" name ="rehousedOn"><br>

          <label for="lstSub">Last Sub. Change</label>
          <input type="date" name="lstSub"><br><br>
          <label for="temperament">Temperament</label>
          <select name="temper" placeholder="Nulear">
              <option>
                  NUCLEAR
              </option>
          </select>
          <div type="container" style="position: absolute; bottom:0; left:0; padding-top: 0px; padding-left: 10px: padding-right: 10px; padding-bottom: 30px; background-color: #3CDBD3; width: 250px; height: 250px; margin-left:10px; margin-bottom: 10px">
           <img style="max-width: 100%; max-height:200%; border-style: solid; border-color: #00FFF5" src="https://imgur.com/OhYxtDB.png" alt="spider"/>
              </form>

          </div>
       </container>
   </div>
    <div class="container" style="width: 1079px; height: 200px; background-color: #7DCE82; position: absolute; bottom:0; right:0; padding-top: 30px; padding-left: 10px: padding-right: 10px; padding-bottom: 30px;">
        <div class="container" style="margin-left: 10px">
        <input type="submit" class="btn btn-dark" value="Add to Database" style="width: 48%; height: 70px;" name="create">" "<input type="submit" class="btn btn-dark" value="Delete Record" style="width: 48%; height: 70px;" name="delete">
        <p> </p>
        <input type="submit" class="btn btn-dark" value="Display Database" style="width: 48%; height: 70px;" name="read">" "<input type="submit" class="btn btn-dark" value="Update" style="width: 48%; height: 70px;" name="update">
        </div>
    </div>
</body>
</html>

functions.php:

<? include "database.php"?>
<?php
function create(){
    global $connection;
    $genus = $_POST['genus'];
    $species = $_POST['species'];
    $lstFed = $_POST['lastfed'];
    $lstHouse = $_POST['rehousedOn'];
    $lstMolt = $_POST['LastMolt'];
    $temper = $_POST['temper'];
    $query = "INSERT INTO spiders VALUES ";
    $query .= "('$genus', '$species', '$lstFed', '$lstHouse', '$lstMolt', $temper)";

    $result = mysqli_query($connection, $query);
    if(!$result){
        die("<h1>FAILED TO ADD VALUE</h1>" );
    }
    else{
        echo "<h1>SPIDER ADDED TO THE DATABASE</h1>";
    }
}
?>

database.php:

<?php
$connection = mysqli_connect("localhost", "root", "", "arappnid");
 if(!$connection){
     die("Database Connection Failed" . mysqli_error($connection));
 }
?>

什么也没发生。

1 个答案:

答案 0 :(得分:0)

您的标记在html中是错误的,首先您要在其中打开<div>,关闭</form>,然后关闭该div

但是您无法得到任何东西的主要原因是因为您的按钮被<form>表单所取代,该表单发送了所有具有内部信息的inputsubmit信息它的标签,现在您有了一个没有发送的表单,并且两个按钮都没有绑定,所以就这样

<form>
...all those fields...` 
<div>...that image...</div>`
<button1></button1>
<button2></button2>
</form>