douliao8760 2013-08-21 04:38
浏览 117

如何使用php和javascript从mysql中删除行

I am trying to delete the entire row using the php code.

But before that my page has a multiple rows ended with radio button before clicking delete button we have to select anyone of the radio button, then we can click on delete.

but what i want is, i have written a java-script code that gets the radio button value and after that i want to get that javascript variable value to php code and then execute the delete command..

Here is what i have tried

code javascript

<script>
function getResults() {
    var radios = document.getElementsByName("address");    
    for (var i = 0; i < radios.length; i++) {       
        if (radios[i].checked) {
        var a = radios[i].value
            alert(a);
            break;
        }
    }
</script>

php code:

  <?php
      $_GET['a']
      mysql_connect("localhost", "tiger", "tiger") or die (mysql_error ());
      mysql_select_db("theaterdb") or die(mysql_error());
      $strSQL =("DELETE FROM theater WHERE theater_name='"$_POST["a"]"'");
      $rs = mysql_query($strSQL);
      mysql_close();
    ?>
    }

But this is not working

i even tried this also.it is also not working

<?php
    if ($_POST['submit'])
    {
      $_GET['a'];
      mysql_connect("localhost", "tiger", "tiger") or die (mysql_error ());
      mysql_select_db("theaterdb") or die(mysql_error());
      $strSQL =("DELETE FROM theater WHERE address='".$_POST["a"]."'");
      $rs = mysql_query($strSQL);
      mysql_close();
      }
    ?>  
  • 写回答

4条回答 默认 最新

  • dqoys62082 2013-08-21 04:40
    关注

    Hey you need to append php variable as below

     $strSQL =("DELETE FROM theater WHERE theater_name='".$_POST["a"]."'");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题