单击按钮时未插入数据


Data not being inserted on button click

如果我不尝试使用按钮单击,我可以在页面加载时正常工作。但是添加按钮单击,我无法将数据插入到我的数据库中。这是 php:

if(isset($_POST['submit']))
{
    $name = "Awesome Name";
    $size = 5.3;
    $color = "black";
    $speciesName = "Tiger";
    $speciesDescription = "Super Test";
    $sql = "INSERT IGNORE INTO tbl_type (Name, Description) VALUES ('$speciesName', '$speciesDescription')";
    $result = mysqli_query($conn, $sql) or die("Query fail: " . mysqli_error($conn));
    $query = "SELECT Id FROM tbl_type WHERE Name = '$speciesName'";
    if($id = $conn->query($query)){
            $row = $id->fetch_assoc();
            $intId = $row['Id'];
    }
    $sql2 = "INSERT INTO tbl_dog (Name, Size, Color, Species) VALUES ('$name', $size, '$color', $intId)";
    $result2 = mysqli_query($conn, $sql2) or die("Query fail: " . mysqli_error($conn));
}

这是我的按钮:

<form action="index.php" method="post">
    <input name="btnInsert" type="submit" value="Insert" />
    <input name="btnUpdate" type="button" value="Update" />
</form>

有一种感觉,我错过了一些愚蠢的东西,我只是说不出它是什么。为什么这不会插入我的数据?

试试这个,

<form action="index.php" method="post">
    <input name="submit" type="submit" value="Insert" />
    <input name="submit_update" type="submit" value="Update" />
</form>