我目前正在開展一個側面項目來運行門票銷售。我創建了一個簡單的網頁與信息的我需要收集<select>標籤不會發布到MySql數據庫
<div id="session" class="tabcontent">
<form action="test.php" method="post" oninput=" totalamount.value = Math.round(adult.value * 10) + Math.round(student.value * 7); changedue.value = Math.round(moneygiven.value - totalamount.value);" id="ticketform">
<fieldset>
<select name=「ticketform」 id="ticketform" form="ticketform">
<option value="" disabled="disabled" selected="selected">Performance</option>
<option value=「1「 type="number" name="showtime1">Show 1 - May 9th 2017</option>
<option value=「2「 type="number" name="showtime2">Show 2 - May 10th 2017</option>
<option value=「3」 type="number" name="showtime3">Show 3 - May 11th 2017</option>
</select>
<h4>Ammount of Adults</h4>
<input name="adult" id="adult" type="number">
<br />
<h4>Ammount of Students</h4>
<input name="student" id="student" type="number">
<br />
<h4>Money Owed</h4>
<output name="totalamount" id="totalamount" for="adult student"></output>
<br />
<h4>Money Given</h4>
<input name="moneygiven" id="moneygiven" type="number">
<h4>Change due</h4>
<output name="changedue" id="changedue" for="moneyowed moneygiven"></output>
<input type="submit" />
</fieldset>
</form>
<footer>
</footer>
但是我遇到的幾個問題的基本知識,並現場這是一個輸出和標記選項將不會被髮送到我的數據庫。
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "TicketSales";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$showtime=$_POST['showtime'];
$adult=$_POST['adult'];
$student=$_POST['student'];
$totalamount=$_POST['totalamount'];
$moneygiven=$_POST['moneygiven'];
$changedue=$_POST['changedue'];
// Insert data into database
$sql="INSERT INTO tickets (showtime, adult, student, totalamount, moneygiven, changedue)
VALUES
('$showtime', '$adult', '$student', '$totalamount', '$moneygiven', '$changedue')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
這是我的發送表單。一切都是鏈接的,任何有輸入標籤的東西都沒有問題。我怎樣才能讓它發送選擇值和輸出?
的可能的複製[PHP得到下拉值和文本(https://stackoverflow.com/questions/6670002/php-get -dropdown-value-and-text) – Sand
警告SQL注入!使用預準備語句:'$ conn-> bind_param' – Akintunde007
切斷問題。檢查你是否獲得了發佈的值(通過檢查'$ _POST')。如果這種情況沒有發生,問題就出現了。如果您執行整個流程並檢查數據庫,則可能會有十幾個步驟處於失敗狀態。 – GolezTrol