duanfei8399 2013-11-26 07:33
浏览 67

在按钮单击时执行sql查询

I had design a form and value of form are showing in table format.In table i have two columns which are buttons Edit and Delete respectively.I want to perform update and delete query on that buttons where id is first column in my table. here is code

<?php
mysql_connect("localhost","root","")or die("Unable to create to connection");
mysql_select_db("sunil") or die(mysql_error());
if(isset($_REQUEST['submit']))
{
    $Id= $_POST["id"];
    $Name1=$_POST["t1"];
    $Name2=$_POST["t2"];
    $Sex=$_POST["sex"];
    $Country=$_POST["Country"];
    $Hobby=$_POST["check"];
    $Email=$_POST["t3"];
    $Pass=$_POST["p1"];
    $Repass=$_POST["p2"];
    $sql="INSERT INTO registration (Your_id,First_Name,Last_Name,Sex,Country,Hobbies,Email,Password,Repassword) VALUES('$Id','$Name1','$Name2','$Sex','$Country','$Hobby','$Email','$Pass','$Repass')";
    mysql_query($sql);
}
$result = mysql_query("SELECT * FROM registration");
print "<table border=1>";
while($row = mysql_fetch_array($result))
{
        print "<tr>";
        print "<td>".$row['Your_id']."</td>";
        print "<td>".$row['First_Name']."</td>";
        print "<td>".$row['Last_Name']."</td>";
        print "<td>".$row['Sex']."</td>";
        print "<td>".$row['Country']."</td>";
        print "<td>".$row['Hobbies']."</td>";
        print "<td>".$row['Email']."</td>";
        echo '<td><input type="submit" value="Edit" onclick="return update()"></td>'; 
// tell me code of update()
        echo '<td><input type="submit" value="Delete" onclick="DELETE FROM registration WHERE Your_id=id"></td>'; 
// tell me what to use in place of is in this line
        print "</tr>";
}
print "</table>";
?>

And here is snap shot

  • 写回答

1条回答 默认 最新

  • doushi3715 2013-11-26 07:48
    关注
        print "<tr>";
        print "<td>".$row['Your_id']."</td>";
        print "<td>".$row['First_Name']."</td>";
        print "<td>".$row['Last_Name']."</td>";
        print "<td>".$row['Sex']."</td>";
        print "<td>".$row['Country']."</td>";
        print "<td>".$row['Hobbies']."</td>";
        print "<td>".$row['Email']."</td>";
        echo '<td><a href="req=update&id=UNIQUE_ID">edit</a>'; 
        echo '<td><a href="req=delete&id=UNIQUE_ID">delete</a>'; 
        print "</tr>";
    

    Now on the starting of the page check for the Request:

    if( isset($_GET['req']) ){
        switch($_GET['req']){
            case 'update':
               // Get the Unique ID
               // and perform your update query with update form
            break;
            case 'delete':
               // Get the Unique ID
               // and perform your delete query
            break;
        }
    }
    

    I give you a basic idea how you can achieve this.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看