0

注文のデータベースがあります。最初のエントリは次のようになります。

id(int)= 1

info_1(varchar)='one'

info_2(varchar)='2'

私は注文を繰り返してHTMLボタンを作成するPHPsciptを使用しています。

while ($temp = mysql_fetch_assoc($query3))
{
   echo "<button id=\"".$temp['id']."\" name=\"delete_but\">Delete</button>";
   // plus some conditions
}

結果:

<button id="1" name="delete_but">Delete</button>
<button id="2" name="delete_but">Delete</button>
<button id="3" name="delete_but">Delete</button>
...
<button id="10" name="add_but">Add</button>
<button id="11" name="add_but">Add</button>
<button id="12" name="add_but">Add</button>
...

ボタンをクリックするとトリガーされるPHPスクリプトを作成するにはどうすればよいですか?テーブルからエントリを削除したいのですが(id == "clicked_button_id")。

また、すべてのユーザーが私のページのHTMLを(すべてのIDとともに)表示できるため、ボタンのID内に注文のIDを入れても安全かどうかを知りたいです。

4

1 に答える 1

0

jQuery:

$('button[name=delete_but]').click(function() {
  $.ajax({
    url: 'deleteEntry.php?id=' + $(this).attr('id')
  }).done(function() {
    $(this).hide();
  });
});

deleteEntry.php:

$entryId = $_GET['id'];

// ...database work to remove the entry with that id...
于 2013-02-16T14:13:17.320 に答える