我有http://www.youngcreatitivy.se插入值到數據庫
後文本的網站你http://www.youngcreativity.se/post.php,我有一個方法後看到。在頁面底部,我有一個選項來選擇文本所屬的類別。我已經創建了這個代碼,用於將選擇框中的值插入到我的數據庫中。這裏是:
<?php
//insert category to database
if(isset($_POST['qty'])) {
// Fetch and clean the <select> value.
// The (int) makes sure the value is really a integer.
$qty = (int)$_POST['qty'];
// Create the INSERT query.
$sql = "INSERT INTO `table`(`quantity`)
VALUES ({$qty})";
// Connect to a database and execute the query.
$dbLink = mysql_connect('server', 'username', 'password') or die(mysql_error());
mysql_select_db('database_name', $dbLink) or die(mysql_errno());
$result = mysql_query($sql);
// Check the results and print the appropriate message.
if($result) {
echo "Record successfully inserted!";
}
else {
echo "Record not inserted! (". mysql_error() .")";
}
}
?>
那就是PHP代碼。
這裏的html代碼:
Qty: <select name="category">
<option value="1">Quote</option>
<option value="1">Poem</option>
<option value="1">Novel</option>
</select>
<br>
<input type="submit">
</select>
我理解的代碼,但是我應該如何創建在phpMyAdmin的數據庫?我怎麼能這樣,如果我選擇類別並在我的文本中鍵入後單擊提交它發佈的文本,它會寫入我在數據庫中選擇的類別? 請幫幫我!
是的,我知道phpmyadmin。我不在本地主機上。但是我應該在表格中創建多少行?我應該在選項之後給它們起名:Quote,Poem and Novel? – tracifycray
通過看到你的代碼高於我的想法是創建一個表的字段名稱ID和數量多數民衆贊成在所有。當你插入的數量值只是那就是爲什麼 – ramsai
數量應該是一個varchar或int? – tracifycray