将变量值传输到另一个页面

时间:2013-11-25 13:56:11

标签: php mysql post

我在页面中有一个SELECT,它列出了数据库中的字段。其中一个字段将是一个链接(公司名称),它将重定向到包含有关此字段的信息的页面。如何传输此数据?每个上市公司都有一个页面。我只需要了解它是如何工作的,因为我尝试使用POST方法而且我有一千个错误。

我感谢任何帮助!

循环和字段

<?php
include("connect.php");

$query = mysql_query("SELECT * FROM table1 ORDER BY nomevaga") or die(mysql_error());

while($array = mysql_fetch_array($query))
{
echo '<div class="field1">'.$array['field1'].'</div>
<div class="company"><a href="company.php">'.$array['company'].'</a></div>';
}
?>

2 个答案:

答案 0 :(得分:0)

您可以通过URL传递值并使用GET:

<?php
include("connect.php");

$query = mysql_query("SELECT * FROM table1 ORDER BY nomevaga") or die(mysql_error());

while($array = mysql_fetch_array($query)) {
    $company = $array['company'];
    echo "<div class='field1'>".$array['field1']."</div><div class='company'><a href='company.php?comp=$company'>".$company."</a></div>";
}
?>

然后在company.php中使用:

$company = $_GET['comp'];
编辑:使用GET和URL参数可能会产生重大安全问题,因为任何用户都可以简单地用自己的URL替换URL中的值,并且取决于您是否使用该变量来加载php文件或将其插入到SQL语句中可能会导致XSS和SQL注入攻击。

答案 1 :(得分:0)

<?php
include("connect.php");

$query = mysql_query("SELECT * FROM table1 ORDER BY nomevaga") or die(mysql_error());

while($array = mysql_fetch_array($query))
{
echo '<div class="field1">'.$array['field1'].'</div>
<div class="company"><a href="company.php?name='.$array['company'].'">'.$array['company'].'</a></div>';
}
?>

company.php
<?php
  $companyName='defaultName';
  if(isset($_GET['name']&&!empty($_GET['name']))
  {
     $companyName=$_GET['name'];
  }
  //handle with  $companyName
?>
相关问题