0

嘿伙计们,我很难发送属于刚刚被点击的 $row['projectnaam'] 的会话变量。目前 Session 总是从 while 循环中获取最后一个 $row['projectnaam'] ,我想知道如何使用属于刚刚单击的行的会话发送正确的变量。

先感谢您。

这是我的语法:

<?php
include "config.php"
$bedrijfsnaam = $_SESSION['gebruikerbedrijf'];
 $result= mysql_query("SELECT * FROM projecten WHERE bedrijfsnaam='$bedrijfsnaam' ")or die(mysql_error());
 while($row = mysql_fetch_array($result)){
     if (isset($_POST['submit'])){

    $_SESSION['projectnaam'] = $projectnaam;
    header('Location: viewprojectsbedrijf.php');
}
     echo "<div class='project'>";
     echo "<div class='projectdetails'>";
     echo "<p class='projectnaam'>";
      echo $row['projectnaam'];
      echo "</p>";
      echo "<hr class='paars'>";
      echo "<p class='datum'>";
      echo $row['datum'];
      echo "|";
      echo $row['Tijd'];
      echo "</p>";
      echo "<hr class='paars'>";
       echo "<p class='bedrijfsnaam'>";
      echo $row['bedrijfsnaam'];
      echo "</p>";
        echo "</div>";
       echo "<div class='view'>";
       echo "<form method=\"POST\" action=\"\">";
      echo "<input type='submit' value='View' name='submit' class='viewbutton'></input>";
     echo "</form>";
        echo "</div>"; 
 }
?>
4

1 回答 1

0

梅德·尼德兰德 ;)

我认为你的意思是做这样的事情:

include("config.php");

if(isset($_POST['submit'])){
    $_SESSION['projectnaam'] = $_POST['projectnaam'];
    header('Location: viewprojectsbedrijf.php');
}
$bedrijfsnaam = $_SESSION['gebruikersbedrijf'];
$result= mysql_query("SELECT * FROM projecten WHERE bedrijfsnaam=".$bedrijfsnaam)or die(mysql_error());
while($row = mysql_fetch_array($result)){
    echo "<div class='project'>
    <div class='projectdetails'>
    <p class='projectnaam'>
    <form method=post action=''>
    <input type=text value=".$row['projectnaam']." name=projectnaam>
    </p>
    </div>
    </div>
    <input type='submit' value='submit' name='submit'>
    </form>";   
}

在您自己的脚本中,只有您的提交按钮位于表单中,因此这将是唯一发布的值。在这种情况下,您将不会获得“projectnaam”的 POST 值。此外,您尝试为未在发布的代码中声明的变量创建 SESSION 值。在我的代码中,它生成 POSTED 代码的 Session 值。

于 2013-10-11T12:40:27.680 回答