English 中文(简体)
php - 删除单页形式的单一记录
原标题:php - delete single record on single page form submit
  • 时间:2012-04-20 15:09:37
  •  标签:
  • php
  • forms

I m pretty new to PHP, see forgive me if this question is obnoxiously noob...

我有一页,从数据库中列出了近150个记录。 我只希望用户能够在某个时候删除一个记录(没有核对箱)。 我想在每一名字旁边有一个删除纽子,当用户点击时,该网页上有更新名单和前面的成功信息:“成功地删除了%的”。 (百分比为删除的实际名称)

我的问题是:我能否以形式这样做? 如果是的话,那么我会把姓名和删除纽特什么形式?

或者,我是否有必要将删除的塔顿列为一个固定内容,而URL则将处理删除请求的网页上,然后将用户重新定位(我的担心是,我能够发出“成功”信息的唯一方式,我知道通过会议变量,是ok?)

或者,我不知道还有什么其他方式?

Any feedback would be greatly appreciated. Thanks

最佳回答

在此,关键概念有一个独特的领域,如数据库中你伪造、姓名、用户名和密码的栏目,在数据库表上对以下两种方式进行了研究:

1,使用超链接

<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$q = mysql_query("SELECT * FROM tbl_name");
if(mysql_num_rows($q)>0)
{
echo"<table>";
echo "<tr><td>name</td><td>action</td></tr>";
while($name = mysql_fetch_assoc($q))
{
?>

<tr><td><?php echo $name[ name ];?></td><td><a href="删除.php?id=<?php echo $name[ id ];?>">Delete</a></td></tr>
<?php
}

echo "</table>";
}
?>

这正是你在列出第...页时所做的。 需要在超文本链接中界定的道路上运行的

删除.php

<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$id = $_GET[ id ];
$q = mysql_query("delete from tbl_name where id =  $id ");
header("Location: list.php");
?>

<>2>。

<?php
    mysql_connect("fostname","username","password");
    mysql_select_db("database_name");
    $q = mysql_query("SELECT * FROM tbl_name");
    if(mysql_num_rows($q)>0)
    {
    echo"<table>";
    echo "<tr><td>name</td><td>action</td></tr>";
    while($name = mysql_fetch_assoc($q))
    {
    ?>

    <tr><td><?php echo $name[ name ];?></td><td><form action= 删除.php  method= post > <input type= hidden  value= <?php echo $name["id"];?> ></form></td></tr>
    <?php
    }

    echo "</table>";
    }
    ?>

删除.php

<?php
    mysql_connect("fostname","username","password");
    mysql_select_db("database_name");
    $id = $_POSTs[ id ];
    $q = mysql_query("delete from tbl_name where id =  $id ");
    header("Location: list.php");
    ?>

(注:清单)。 页: 1

问题回答

为什么必须成为一种/一种形式? 你可以使用链接,删除诸如href=”#?job=delete&等单一条目;名称=姓名而不是提交纽州。 另一种解决办法是为每个入境建立一个表格。

您可以使用载有你的数据的网页(say A)。

When you have it, you can "anchor" a link on the button for each element (assigning a costum id for identify it). Once you click on the button, you add in the built-in array $_GET the id of the record that you have erased (obv. you have to erase it). Now you can redirect to the same page (A).

On this page (that is the same page where you have initial data) you check for $_GET field that you added. If it is that means that you come there after a delete and you can display the message. Otherwise is the very first time you enter here, so you haven t to display nothing.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签