How to display data from Mysql table using dynamic links ?

Solved/Closed
Anonymous User - Updated on Feb 27, 2019 at 12:34 PM
 Anonymous User - Feb 28, 2019 at 07:14 AM
Hello,
I search for some tutorials about this subject but I don't find any.
This is my php link on page1.php :

<a href="page2.php?word=car">car</a>

And this is the operation I try to execute on page2.php :

$sql = "SELECT * FROM mytable WHERE word='$word'";

I also tried using word='$_GET['word']' but I only obtain syntax errors.
And this is my code on page2.php :

<?php
$con=mysqli_connect("localhost","root","my password","my database") or die(mysql_error());
$output = ' ';
$word = $_GET['word'];

$sql = "SELECT * FROM mytable WHERE word='$word'";
$query = mysqli_query($con,$sql)

$count = mysqli_num_rows($query);

while($row = mysqli_fetch_array($query)) {
$word = $row['word'];
$definition = $row['definition'];
$id = $row['id'];

$output .= '<div>'.$word.' '.$definition.'</div>';
}
?>

Thank you.

1 response

Blocked Profile
Feb 27, 2019 at 12:31 PM
Take a look at Mr Greens code example here.
0
Hello,
I finally came to a conclusion, the problem was not the code, the problem was wamp server because the same code works perfectly on 000webhost server so I have a question, is wamp server really reliable to learn and make tests ?

As an alternative I downloaded xamp server for windows but during the insalation I get a warning message about an eventual conflict between xamp and my antivirus, I don't understand this message, therefore I don't dare continue the installation process.

Best regards,
0