duanbipu7601 2012-10-01 07:39
浏览 28
已采纳

php mysql删除语句

First of all I am displaying a list of values in a table, What I am trying to do is add a delete button based off of the tables unique table id.

So I am trying to delete a value from my database using a this button i have declared, however with what I am doing at the moment it's just not deleting anything to the database.

This is my database table

CREATE TABLE `5050goosedown` (
    `goosedown_id` int(11) unsigned NOT NULL auto_increment,
    `name` varchar(100) NOT NULL default '',  
    `width` int(8),
    `height` int(8),
    `normal_fill` int(8),
    `our_fill` int(8),
    `old_price` DECIMAL(3,2),
    `price` DECIMAL(3,2), 
    PRIMARY KEY  (`goosedown_id`)
    ) TYPE=MyISAM;

this is my button, its inside a form which reloads this same page..

echo '<td><input type="submit" name="'.$row['goosedown_id'].'" value="Delete" /></td>"';

So this is a button that says Delete, and its name is the unique id of that table... (one of the several tabels I have and would like to do this on)

Then when the page reloads I have this if statement to capture the particular delete button being pressed... which is not working atm..

//DELETE QUERIES
if(isset($_POST['goosedown_id']) and is_numeric($_POST['goosedown_id']))
{
  // here comes your delete query: use $_POST['deleteItem'] as your id
  mysql_query("DELETE FROM 5050goosedown WHERE goosedown_id='goosedown_id'");
}
  • 写回答

3条回答 默认 最新

  • dpje52239 2012-10-01 07:43
    关注

    Change your HTML to:

    echo '<td><form method="post" action=""><input type="hidden" name="goosedown_id" value="'.$row['goosedown_id'].'" /><input type="submit" name="sumbit" value="Delete" /></form></td>"';
    

    and script:

    if(isset($_POST['goosedown_id']) and is_numeric($_POST['goosedown_id'])){
      mysql_query("DELETE FROM 5050goosedown WHERE goosedown_id=".(int)$_POST['goosedown_id']);
    }
    

    You do not pass the ID with sumbit button as it's value is Delete, you need to create an hidden field.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效