Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to insert user input values from my HTML form into my mysqli db. At this point I'm not getting an error message anymore. I just end up on a blank screen after pressing submit on the form.

What I have tried:

HTML CODE

HTML
<!DOCTYPE html>
<html> 
<head>
<title> Pasta Mix </title>

</head>

<body>

<h1> Enter your mix to add to the list! <h1/>
<form method="post" action="PastaList.php">

<label> Sauce: </label>
<select name="sauce">
  <option value="alfredo">Alfredo</option>
  <option value="tomato">Tomato</option>
</select>

<label> Meat: </label>
 <select name="meat">
  <option value="chicken">Chicken</option>
  <option value="meatballs">Meatballs</option>
  <option value="shrimp">Shrimp</option>
  <option value="sausage">Sausage</option>
</select>

<label> Noodle: </label>
 <select name="noodle">
  <option value="spaghetti">Spaghetti</option>
  <option value="fettuccine">Fettuccine</option>
  <option value="penne">Penne</option>
  <option value="corkscrew">Corkscrew</option>
</select>

<input type="submit" value="Submit"/>

</form>
  
</body>

</html>




PHP CODE

PHP
<?php


$servername = "localhost";
$username = "kaylahblack";
$password = "";
$dbname = "pastalist";

$conn = mysqli_connect('localhost','kaylahblack','', 'pastalist');

if(isset($_POST['submit']))
{
$sauce=$_POST['sauce'];
$meat=$_POST['meat'];
$noodle=$_POST['noodle'];

$sql = "INSERT INTO pastalistt (sauce, meat, noodle)
VALUES ('$sauce', '$meat', '$noodle')";
$result=mysqli_query($sql);


if($result){
echo "Pasta Added!";
}
}

mysqli_close($conn);
?>
Posted
Updated 8-Sep-18 2:16am
Comments

1 solution

The PastaList.php is expecting a
$_POST['submit']
but it is not available!
Ask yourself what is this 'submit' thing? You are missing something in the html form. You have done it right for the select elements, take reference from them.
Check this out Form Handling with PHP[^]
If you have time, you should google for SQL injection and learn how to construct SQL statement safely.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900