I have one table with 4 columns (id, name, surname, url). I want to create unique subpage for each row. (example.com/id?=444). So if I visit example.com?id=444 I will see data from row which has id 444.
Right now I have form where you add data into database:
<form action="motogp.php" method="POST"> <input type="text"
name="name" placeholder="Ime"> <input type="text" name="surname"
placeholder="Priimek"> <input type="text" name="url" placeholder="URL
do slike"> <button type="reset" class="ui button">Počisti</button>
<button type="submit" class="ui positive button">Pošlji</button>
</form>
motogp.php page code:
$sql="INSERT INTO person (name, surname, url)
VALUES
('$_POST[name]','$_POST[sruname]','$_POST[url]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
$result = mysqli_query($con,"SELECT * FROM person ORDER BY id DESC LIMIT 1");
while($row = mysqli_fetch_array($result))
{
echo "<h2>VIDEO: " . $row['name'] . . $row['surname'] . " z drugo zaporedno zmago zmanjšal zaostanek za Marquezom</h2>";
echo "<img src='images/avoter.png'>";
echo "<img src='" . $row['url'] ."'>";
}
Now it gives me just example.com/motogp.php not example.com/?id=444.
You need to use $_GET[''] rather than $_POST[''].
GET sends through all of your data through the URL in a format that is donated by
website.com/page.php?v=d&v=d
where v is a variable and d is some sort of data assigned to it. If you want dynamically created pages. You need to send it through GET
So if the page you want is website.com/page.php?id=4 in order to grab the data from the database entry with id 4 you need to do something like so
<?php
$id = $_GET['id']; //in the case of the URL above, it will equal four
?>
Then you take that $id variable and run it through query grabbing the specific data you need.
If you want to make a form that sends the data over GET rather than POST, you just need to change the part where it says method="post" to method="get"
I hope this helped!
EDIT:
Say you had a few links:
website.com/page.php?id=1
website.com/page.php?id=2
website.com/page.php?id=3
on page.php's code you can see what 'id' is equal to by using the code:
$var = $_GET['id'];
that will get the value of id out of the url.
So for website.com/page.php?id=1 $var is equal to 1,
for website.com/page.php?id=2 $var is equal to 2,
for website.com/page.php?id=3 $var is equal to 3,