I've got this working normally on page load if I don't try to use a button click. But adding the button click, I'm unable to get the data to insert into my database. Here's the 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));
}
And here's my button:
<form action="index.php" method="post">
<input name="btnInsert" type="submit" value="Insert" />
<input name="btnUpdate" type="button" value="Update" />
</form>
I have the feeling I'm missing something silly, I just can't tell what it is. Why will this not insert my data?