2017-12-06 17:26
浏览 33

未从PHP HTML表单提交的值[关闭]

I am trying to take the input from drop down menus that users enter and submit them to a table in my database. I am trying to submit the values into this table: enter image description here I use the POST to check that the values are being pulled from the HTML form and they are, but they won't submit into my table. I've made sure that all of the names with the columns and HTML forms are correct, why won't the values post to the table?


$databaseName = 'pizza_db';
$databaseUser = 'root';
$databasePassword = 'root';
$databaseHost = '';
$conn = new mysqli($databaseHost, $databaseUser, $databasePassword, $databaseName);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "Connected sucessfully

$value = mysqli_real_escape_string($conn,$_POST['drink']);
$value2 = mysqli_real_escape_string($conn,$_POST['cheese']);
$value3 = mysqli_real_escape_string($conn,$_POST['veggies']);
$value4 = mysqli_real_escape_string($conn,$_POST['meat']);
$value5 = mysqli_real_escape_string($conn,$_POST['sauce']);
$value6 = mysqli_real_escape_string($conn,$_POST['crust']);
$value7 = mysqli_real_escape_string($conn,$_POST['size']);

$sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size) 

//Here I am posting the values to check that they are being submitted 
echo $_POST["size"];
echo "
echo $_POST["sauce"];
echo "
echo $_POST["crust"];
echo "
echo $_POST["cheese"];
echo "
echo $_POST["meat"];
echo "
echo $_POST["veggies"];
echo "
echo $_POST["drink"];

<!DOCTYPE html>
<form action='' method='post'>

<p>Choose a size<p>
<select id="size" name="size">
  <option value="small">Small</option>
  <option value="medium">Medium</option>
  <option value="large">Large</option>
  <option value="x-large">X-large</option>

<p> Choose a sauce <p>
<select id="sauce" name="sauce">
  <option value="none">None</option>
  <option value="marinara">Marinara</option>
  <option value="alfredo">Alfredo</option>
  <option value="ranch">Ranch</option>
  <option value="bbq">BBQ</option>

<p> Choose a cheese<p>
<select id="cheese" name="cheese">
  <option value="none">None</option>
  <option value="mozzarelaa">Mozarella</option>
  <option value="cheddar">Cheddar</option>
  <option value="parmesan">Parmesan</option>
  <option value="three cheese">Three-Cheese</option>

<p> Choose a meat <p>
<select id="meat" name="meat">
  <option value="none">None</option>
  <option value="Pepperroni">Pepperroni</option>
  <option value="sausage">Sausage</option>
  <option value="bacon">Bacon</option>
  <option value="canadian bacon">Canadian Bacon</option>
  <option value="chicken">Chicken</option>
  <option value="salami">Beef</option>
  <option value="anchovies">Anchovies</option>

<p> Choose a veggies <p>
<select id="veggies" name="veggies">
  <option value="none">None</option>
  <option value="onions">Onions</option>
  <option value="green peppers">Green Peppers</option>
  <option value="Red peppers">Red peppers</option>
  <option value="Black olives">Mushrooms</option>
   <option value="jalapenos">Jalapenos</option>
    <option value="tomatoes">Tomatoes</option>
    <option value="pineapple">Pineapple</option>

<p> Choose a crust <p>
<select id="crust" name="crust">
  <option value="regular">Regular</option>
  <option value="deep-dish">Deep-dish</option>
  <option value="thin-crust">Thin Crust</option>
  <option value="stuffed crust">Stuffed Crust</option>
  <option value="gluten free">Gluten Free</option>

<p> Choose a drink <p>
<select id="drink" name="drink">
  <option value="none">None</option>
  <option value="rootbeer">Root Beer</option>
  <option value="coke">Coke</option>
  <option value="diet coke">Diet Coke</option>
  <option value="dr pepper">Dr Pepper</option>
<input type="submit" name="submit" value="Submit"/>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanlisha2335 2017-12-06 17:30

    Seems like you are not running the query.

    // sql
    $sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size) 
    // run query
    mysqli_query($conn, $sql);
    // or
    打赏 评论
  • douyin2962 2017-12-06 17:34

    You prepared string query but you are not executing it.

    $sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size) 
    // run query with below mentioned function
    mysqli_query($conn, $sql);

    Then check your table. You will see the data saved.

    打赏 评论

相关推荐 更多相似问题