开发者

PHP How to pass variables through a link to the next php file

开发者 https://www.devze.com 2023-04-11 01:45 出处:网络
echo \"<td>\" . \"<a href=\'approve_mem.php?id=$row[\'member_id\']\'>Approve</a>\" . \" \" .
echo "<td>" . 
    "<a href='approve_mem.php?id=$row['member_id']'>Approve</a>" . " " . 
    '<a href="disapprove_mem.php?id=$row[member_id]">Disapprove</a>' .
"</td>";

This is my code but the value of id does not get passed instead it gets passed like id=$row['member开发者_如何转开发_id'] as it is, and when I echoed the id variable it got printed like $row['member_id']


Rather than building HTML strings in PHP, I recommend you only switch to the PHP context when required, eg

<td>
    <a href="approve_mem.php?id=<?php echo htmlspecialchars($row['member_id']) ?>">Approve</a>
    <a href="disapprove_mem.php?id=<?php echo htmlspecialchars($row['member_id']) ?>">Disapprove</a>
</td>


Try this:

echo "<td>" . 
"<a href='approve_mem.php?id=".$row['member_id']."'>Approve</a>" . " " . 
'<a href="disapprove_mem.php?id='.$row['member_id'].'">Disapprove</a>' ."</td>";


You need to change it to:-

echo "<td>" . 
    "<a href='approve_mem.php?id={$row['member_id']}'>Approve</a>" . " " . 
    "<a href='disapprove_mem.php?id={$row['member_id']}'>Disapprove</a>" .
"</td>";  

Notice the use of curly braces and the change of quotes used in the second line. Also you hadn't quoted member_id in your second use of $row['member_id']

Also take note of Dagon's comment above.


I am guessing this is part of a database query. You have to seperate the data from the string in this instance. This can be written two ways:

 <td>
   <a href='approve_mem.php?id=<?php echo $row['member_id']; ?>'>Approve</a> <a href="disapprove_mem.php?id=<?php echo $row['member_id']; ?>">Disapprove</a>
 </td>

------------- OR -------------

 echo "<td><a href='approve_mem.php?id=".$row['member_id']."'>Approve</a> <a href='disapprove_mem.php?id=".$row['member_id']."'>Disapprove</a></td>";


change that to this:

  echo "<td><a href=\"approve_mem.php?id=".$row['member_id']."\">Approve</a>
  <a href=\"disapprove_mem.php?id=".$row['member_id']."\">Disapprove</a></td>";

or

 <td>
       <a href='approve_mem.php?id=<?=$row['member_id']?>'>Approve</a>
       <a href='disapprove_mem.php?id=<?=$row['member_id']?>'>Disapprove</a>
 </td>
0

精彩评论

暂无评论...
验证码 换一张
取 消