Reputation: 151
I have some data displayed from SQL to PHP, when the user clicks the eye icon, he is redirected to another page with id on the URL, I did the following code
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><a href="detail.php?id=$record['id']\"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
</tr>
<?php } ?>
Instead of the id, some special characters are coming in the URL, how can I fix it?
Upvotes: 3
Views: 1051
Reputation: 3733
You should echo it, like you did with another values:
<?php echo $record['id']; ?>
Full code:
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><a href="detail.php?id=<?php echo $record['id']; ?>\"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
</tr>
<?php } ?>
Upvotes: 2
Reputation: 5322
You should echo ID
as below
<a href="detail.php?id=<?= $record['id'] ?>\">
Upvotes: 0
Reputation: 3476
Below is how your anchor tag should be.
<a href="detail.php?id=<?php echo $record['id']; ?>\"><i class="fa fa-eye" aria-hidden="true"></i></a>
You need to enclose the $record variable inside php tags and echo it.
Upvotes: 4