Select語句
<?php
$q = $db->prepare('SELECT album_id, album_name
FROM table_albums ORDER BY album_name');
$q->bindParam(':album_id', $album_id);
$q->bindParam(':album_name', $album_name);
$q->execute();
的最後一個值只用HTML這裏
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title><?php echo basename(__FILE__); ?></title>
</head>
<body>
<h1>Add Tracts</h1>
<form method="post">
Tracks Name:<br>
<input type="text" name="tracks_name" value="<?php $tracks_name ?>"><br>
<select>
<option name="album_id" id="album_id">Select</option>
<?php while ($row = $q->fetch()) { ?>
<option value="<?php echo $row->album_id;?>">
這是我認爲這個問題是
<?php echo $row->album_name; $album_id = $row->album_id;?>
</option>
<?php } ?>
</select>
<input type="submit" value="Submit now"/>
</form>
只處理表格如果$ _POST不爲空
<?php
if (! empty($_POST)) {
$stmt = $db->prepare("INSERT INTO table_tracks
(tracks_name, tracks_id, album_id)
VALUE (:tracks_name, :tracks_id, :album_id)");
$stmt->bindParam(':tracks_id', $tracks_id);
$stmt->bindParam(':tracks_name', $tracks_name);
$stmt->bindParam(':album_id', $album_id);
插入一行
$tracks_name = $_POST["tracks_name"];
$stmt->execute();
}
?>
</body>
</html>
album_id總是在數據庫 的最後一個值,我不知道該怎麼辦
$ _ POST只有一個單元,it.array(大小= 1) 'tracks_name'=>字符串 'VVV'(長度= 3) – dgs
@dgs因爲你需要改變你的''