私は、テーブルに製品を表示するPHPとMySQLを使用してウィッシュリストのWebサイトを開発しています。ユーザーは、それぞれの製品を自分の希望リストに追加するオプションがあります。PHP MYSQL:テーブルの内容を表示して別のテーブルに追加
商品を表示することはできますが、ユーザーが自分のリストに追加するオプションをクリックすると、何も得られません。私が実行しているサーバもエラーを表示しないので、何が間違っているのか分かりません。
ご協力いただければ幸いです。私は以下のコードを含んでいます。
<?php
//connect to db
include('base.php');
//get results from db
$result = mysql_query("SELECT * FROM coffee_machines")
or die(mysql_error());
echo "<table border= '1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Brand</th> <th>Description</th> <th>Price(£)</th> <th>image</th> </tr>";
$img_url = "http://localhost:8080/";
//loop through results of db query so items are displayed
while($row = mysql_fetch_array($result)){
// echo out contents of each row
echo '<tr>';
echo '<tr>';
echo '<td>'.$row["Product_ID"].'</td>';
echo '<td>'.$row["Brand"].'</td>';
echo '<td>'.$row["Description"].'</td>';
echo '<td>'.$row["Price"].'</td>';
echo '<td>'.'<img src="'.$img_url.$row['image'].'" /></td>';
echo '<td>'.'<a href = "?Add To List">Add To List</a></td>';
echo '</tr';
echo '</tr';
$add_to_list = "INSERT INTO andrew VALUES('".$row["Product_ID"]."', '".$row["Brand"]."', '".$row["Description"]."', '".$row["Price"]."', '".$row["image"]."')";
if(isset($_POST['Add To List'])){
mysql_query($add_to_list);
}
//close table
echo "</table>";
?>
これは動作しません。あなたは$ _POSTを待ち、あなたのリンクは$ _GETを返します。 – Amazone
これを修正するには、POSTをGETに変更する必要がありますか? – ConorMcC
[mysql_'データベース拡張](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)を使用しないでください。 は廃止予定ですPHP7で)特にPHPを学んでいるならば、あなたのエネルギーを 'PDO'データベース拡張を学ぶのに費やしてください。 [こちらから](http://php.net/manual/en/book.pdo.php)そのとてもかわいいです。 – RiggsFolly