我有一個擁有'植物'主題的數據庫。我想要一個腳本來檢索玫瑰植物的細節並將這些值放入字段中。然後,我希望用戶能夠更新該項目並將其提交回數據庫。在窗體中使用SELECT和UPDATE查詢
我希望用戶從它的拉丁名數據庫這是在「玫瑰」表中的唯一屬性,拉項目。這裏是插入一個玫瑰的代碼,可能有人請幫助我適應這個吧,請使用預處理語句我多麼希望:
//connect to database
$conn2 = DB2();
require_once('header_admin.php');
/*
if (isset($_POST['addrose']))
{
//detect if we have errors or not
$errors = false;
$error_msg = "Error, please try again";
/*
* Could do other validation here
* Make sure they enter an email address for example
*/
//if we have no errors, do the SQL
if (!$errors) {
$latin_name = $_POST['latin_name'];
$common_name = $_POST['common_name'];
$variety_name = $_POST['variety_name'];
$colour = $_POST['colour'];
$season = $_POST['season'];
$hardiness = $_POST['hardiness'];
$situation = $_POST['situation'];
$soil_type = $_POST['soil_type'];
$price = $_POST['price'];
$fragrance = $_POST['fragrance'];
$height = $_POST['height'];
//insert data
$stmt = $conn2->prepare("INSERT INTO rosename (latin_name, common_name, variety_name, colour, season_of_interest, hardiness, situation, soil_type, price,
fragrance, ultimate_height) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
//bind the parameters
$stmt->bind_param('ssssssssdss', $latin_name, $common_name, $variety_name, $colour, $season, $hardiness, $situation, $soil_type, $price, $fragrance,
$height);
// Execute query
$stmt->execute();
//if the query worked, put out the confirmation message (you can make this look however you want)
if ($stmt) {
echo "<p class='black'>Rose Added!</p>";
爲什麼不使用框架? – Teson 2012-02-28 08:29:30