简体   繁体   English

如何获取PHP行值?

[英]How to get php row values?

management.php is the code which get information in php by a table. management.php是通过表在php中获取信息的代码。 And managementdel.php is the code which del the information. 而managementdel.php是删除信息的代码。 I use mysql_fetch_array to show all data,and beside every information have a herf to delete echo data in database. 我使用mysql_fetch_array来显示所有数据,并且每个信息旁边都有一个herf来删除数据库中的回显数据。

When I del ,there no error inside.but database information haven't delete. 当我删除时,里面没有错误。但是数据库信息尚未删除。

management.php management.php

 $con1 = mysql_connect("127.0.0.1","root","password");

      mysql_select_db("babytradeapps");

      $sql1 = "Select LoginID , Password , Permission
              from loginacc where Permission = 2 ";


      $results = mysql_query($sql1,$con1);

       echo "<tr><th>會員帳號</th></tr>";

      echo "<table border=5 cellpadding=10>";

      echo "<tr><th></th><th>帳號</th><th>密碼</th><th>權限</th><th></th><th></th></tr>";

      while($row = mysql_fetch_array($results)) { 

       echo "<tr><td>
        <a href='searchtable.php?lid=$row[0]'>get information</a></td><td>$row[0]</td><td><input type=text id='row1' name='row1' value='$row[1]' /></td>
                  <td>$row[2]</td><td>
                  <a href='searchtable.php?lid=$row[0]'>Change</a></td><td>
                  <a href='managementdel.php?lid=$row[0]'>Delete</a></td></tr>";

      }

      echo "</table>";

managementdel.php managementdel.php

<?php

$ac = $_GET['rowname'];

 $con = mysql_connect("127.0.0.1","root","password");

  mysql_select_db("babytradeapps");

  $sql = "delete from loginacc where LoginID = '$ac'";   




  if(mysql_query($sql))

  {
               echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';

        }
        else
        {
                echo 'fail!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
        }


echo mysql_error()
?>

There is so much stuff wrong with your script, I won't address it all. 您的脚本有太多错误,我不会全部解决。 What I will do is answer your question that you asked which is: "Why it won't delete from database." 我要做的是回答您所问的问题: “为什么它不会从数据库中删除”。

What is wrong in your script: 您的脚本出了什么问题:

  • Using depreciated mysql_* library ( See notes below ) 使用折旧的mysql_*库( 请参见下面的注释
  • Using meta refresh to redirect instead of something like header('Location: link'); 使用meta refresh来重定向,而不是诸如header('Location: link');类的东西header('Location: link');
  • Not sanitizing user input -> $_GET['lid'] . 不清除用户输入-> $_GET['lid']
  • Posting user password in the table. 在表中发布用户密码。 ( Hopefully not being stored as plaintext ) 希望不会以纯文本格式存储

As stated, you're trying to get: 如前所述,您正在尝试获得:

$_GET['rowname']

When you are sending lid -> managementdel.php?lid=$row[0] . 当您发送lid -> managementdel.php?lid=$row[0] You have to change that to: 您必须将其更改为:

$ac = $_GET['lid'];

NOTES 笔记

Please stay away from mysql_* functions as the library is depreciated. 请不要使用mysql_*函数,因为该库已mysql_*

Use either of the following two instead: 请改用以下两个方法之一

And if you aren't going to do that, atleast try and sanitize your user inputs to prevent SQL Injections. 而且,如果您不打算这样做,请至少尝试清理用户输入以防止SQL注入。

Using functions like intval() and mysql_real_escape_string() will help you but won't be as comprehensive as PDO/mysqli. 使用intval()mysql_real_escape_string()类的函数将对您有所帮助,但不会像PDO / mysqli那样全面。

in managementdel.php file instead of 在managementdel.php文件而不是

$ac = $_GET['rowname'];

there should be 应该有

$ac = $_GET['lid'];

Try 尝试

management.php management.php

<?php
 $con1 = mysql_connect("127.0.0.1","root","password");

      mysql_select_db("babytradeapps");

      $sql1 = "Select LoginID , Password , Permission
              from loginacc where Permission = 2 ";


      $results = mysql_query($sql1,$con1);

       echo "<tr><th>會員帳號</th></tr>";

      echo "<table border=5 cellpadding=10>";

      echo "<tr><th></th><th>帳號</th><th>密碼</th><th>權限</th><th></th><th></th></tr>";

      while($row = mysql_fetch_array($results)) { 

       echo "<tr><td>
        <a href='searchtable.php?lid= " . $row[0] . "'>get information</a></td><td>" . $row[0] . "</td><td><input type=text id='row1' name='row1' value='" . $row[1] . "' /></td>
                  <td>" . $row[2] . "</td><td>
                  <a href='searchtable.php?lid=" . $row[0] . "'>Change</a></td><td>
                  <a href='managementdel.php?lid=" . $row[0] . "'>Delete</a></td></tr>";

      }

      echo "</table>";

?>

managementdel.php managementdel.php

<?php

$ac = $_GET['lid'];

 $con = mysql_connect("127.0.0.1","root","password");

  mysql_select_db("babytradeapps");

  $sql = "delete from loginacc where LoginID = '$ac'";   




  if(mysql_query($sql))

  {
               echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';

        }
        else
        {
                echo 'fail!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=management.php>';
        }


echo mysql_error()
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM