0

I'm sorry if this is unclear or difficult to understand, but explaining what I am attempting to do isn't that easy over text. In the HTML code like this entry works:

<th><a href="members.php?id=<?php echo 'name';?>&action=<?php echo $action;?>">Name</a></th>
<td><?php echo $row["name"];?></td>

but in PHP I can not advise:

echo "<th><a href="members.php?id=<?php echo 'name';?>&action=<?php echo $action;?>">Name</a></th>";
echo "<td><?php echo $row["name"];?></td>";

"id" has value /name, lastname, city, district/ 
"action" has value /ASC, DESC/

Complete table for clarity I not want to indicate. Can you help me?

Now I have:

echo "<th><a href=\"members.php?id=<?php echo 'name';?\>&action=<?php echo $action;?\>\">Name</a></th>";
echo "<td><?php echo '".$row['name']."';?\></td>";

expected result in URL is:

.../members.php?id=name&action=ASC

but my is:

.../members.php?id=<?php%20echo%20%27name%27;?\>&action=<?php%20echo%20;?\>

can you anybody help me?

Edit 2

$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '<th><a href="members.php?id='.$row['name'].'&action=' . $action . '">Name</a></th>';

while($row = $result->fetch_assoc()) {
echo '<td> ' . $row['name'] . '</td>';

Undefined variable: 'row'

can you help me?

piitr
  • 35
  • 1
  • 8
  • You need to escape your quotation marks. Duplicate of: [Escaping quotation marks in PHP](http://stackoverflow.com/questions/7999148/escaping-quotation-marks-in-php) – icecub Apr 10 '16 at 22:47
  • Unfortunately, I cannot self advise with this problem. Have you any different idea, or solving? Please. – piitr Apr 10 '16 at 23:56
  • As I've already said: Escape quotation marks: `echo " – icecub Apr 11 '16 at 00:26

2 Answers2

0

Try this. When you echoes that is already between <?php tags.

<?php
echo '<th><a href="members.php?id='.$row['name'].'&action=' . $action . '">Name</a></th>';
echo '<td> ' . $row['name'] . '</td>';
?>

But I suggest you to use it as a template, not from PHP (this is html code)

<th><a href="members.php?id=<?php echo $row['name']; ?>&action=<?php echo $action; ?>">Name</a></th>
<td><?php echo $row['name']; ?></td>;
vaso123
  • 12,347
  • 4
  • 34
  • 64
  • The first part works ..... But second no Result by clicking on header is: `Trying to get property of non-object in` I have: `$result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) {` – piitr Apr 11 '16 at 11:51
  • Your connection to the server, or your query has failed. – vaso123 Apr 11 '16 at 12:01
0

Try this code 100% working..

echo '<th><a href="members.php?id='$name'&action='$action"'>Name</a></th>';
echo '<td>'$row["name"]'</td>';
john
  • 31
  • 1
  • 1
  • 8
  • I am sorry, no working, because `unexpected $name` is variable `name/lastname/city/district` – piitr Apr 11 '16 at 12:13