-1

I have a table that draws information from my MYSQL database. I have a button that I want to echo the id of the row of the information I draw. I can echo all the information to the table but for some reason no idea how to get the information into the URL

I want to use it in the next page in the GET function for additional data being drawn

 echo "<td> <a href='dashboard.php?id="<php echo[id], ?>"'><button>Next</button></a> </td>";

I am receiving this error:

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in

The unexpected Echo they referring to I think is the second one as the first echo on previous rows in my table I have no issues

Update:

I have this sql string:

$sql = "SELECT * FROM new_case WHERE status = 'Active'";

In the table I have one row as below and it shows the id of that row.

echo "<td>" . $row['id'] . "</td>";
  • 1
    You should really rather go and find yourself a beginner’s tutorial that explains the basics of the syntax. Stuff that is as extremely low-level as this, should not be asked about here in the first place, this is not a teaching ground. – 04FS Dec 06 '19 at 12:15
  • 1
    @04FS Thanks for the comment as this is low-level for you it is a milestone for me – James Brown Dec 06 '19 at 12:17
  • @JamesBrown --> $id = $row['id']; echo ""; can you try this? – BhAvik Gajjar Dec 06 '19 at 12:23

3 Answers3

1

You made mistake here <php echo[id], ?>

you are already inside PHP, so dont use <?php ?>

also echo[id] is not valid, PHP variable start with $

So replace your line with below line.

 echo "<td> <a href='dashboard.php?id=".$row['id']."'><button>Next</button></a> </td>";
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
0

It seems there is a typo at the echo function, the syntax of the echo function is echo <string> you can see it in the documentation.

So calling echo[id] is invalid syntax, it expects a string of some sorts (this can be a variable too, as long as it implements a __toString function).

A right way to call it would be like echo "<td><a href='dashboard.php?id=$id'"... when you use double quotes PHP will try to interpit the quote and parse any variables written inside of it.

However, it is important to know that is is a security risk to directly output database information into an URL.

AngelsDustz
  • 64
  • 1
  • 7
0

Please use below code

echo "<td> <a href='dashboard.php?id=".$id."'><button>Next</button></a> </td>";

instead of

 echo "<td> <a href='dashboard.php?id="<php echo[id], ?>"'><button>Next</button></a> </td>";