php - Creating dynamic url doesn't work when using other variable than id -
i'm creating dynamic webpages website.
i got archive.php file use following code:
code archive.php:
<?php (connect database) $id = $_get['id']; $sql = "select * `table-example` id = $id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo $row['text']; }// end while }// end if else { echo '0 results';} ?>
link dynamic page:
<a href="/archive?id=<?php echo $row['id'];?>">
example of variable "id" in database:
123
result:
when access page, opens http://example.com/archive?id=123 correct data.
so far, good. problem want create url variable database. changed code this:
code archive.php:
<?php (connect database) $url = $_get['url']; $sql = "select * `table-example` url = $url"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo $row['text']; }// end while }// end if else { echo '0 results';} ?>
link dynamic page:
<a href="/archive?url=<?php echo $row['url'];?>">
example of variable "url" in database:
this-is-a-new-article
result:
0 results.
important note: know i'm open mysqli injection! i'm going change code after fixed problem.
you need quotes because string
where url = '$url'
Comments
Post a Comment