I've tried a few different answers given on this site, I still can't seem to get everything to work properly. I will post what I currently have.
My Database name is "artStore"
My Table name is "inventory"
My HTML code for the form is:
<form action="sendToTable.php" method="post">
<h3>Product:</h3>
<input type="text" name="$row[product]">
<h3>Category:</h3>
<input type="text" name="$row[category]">
<h3>Seller:</h3>
<input type="text" name="$row[seller]">
<input type="submit">
</form>
My PHP code for sending the information to the database:
$sql = "INSERT INTO inventory (id, product, category, seller) VALUES ('$row[id]', '$row[product]', '$row[category]', '$row[seller]')";
//Run the sql statement
if ($connection->query($sql) === true) {
echo "The Insert Worked";
} else {
echo "Error occured in the insert: " . $connection->error;
}
$connection->close();
My PHP code for displaying the table:
$sql = "SELECT * FROM inventory";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "
id: $row[id] <br>
product: $row[product] <br>
category: $row[category] <br>
seller: $row[seller] <br>
<hr>
";
}
} else {
echo "No Results";
}
$connection->close();
Any help is much appreciated! I'm new to Web Programming.
EDIT 1:
I updated my files and the Error I get says:
"Error occured in the insert: Column count doesn't match value count at row 1"
It says that the error is occurring in the file containing PHP Code for sending Info to the Database, but here are all my files.
HTML code for the Form:
<form action="sendToTable.php" method="post">
<h3>Product:</h3>
<input type="text" name="product">
<h3>Category:</h3>
<input type="text" name="category">
<h3>Seller:</h3>
<input type="text" name="seller">
<input type="submit">
</form>
PHP Code for sending Info to the Database:
//Create the SQL Statement
$product = $_POST['product'];
$category = $_POST['category'];
$seller = $_POST['seller'];
$sql = "INSERT INTO inventory (id, product, category, seller) VALUES ('$product', '$category', '$seller')";
//Run the sql statement
if ($connection->query($sql) === true) {
echo "The Insert Worked";
} else {
echo "Error occured in the insert: " . $connection->error;
}
$connection->close();
PHP Code for Displaying the Table:
$sql = "SELECT * FROM inventory";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "
id: $row[id] <br>
product: $row[product] <br>
category: $row[category] <br>
seller: $row[seller] <br>
<hr>
";
}
} else {
echo "No Results";
}
$connection->close();