0

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.

3
  • example.com/?id=444 is shorthand for example.com/index.php?id=444 (or whatever your default DirectoryIndex page is, index.html, etc). Have you created that page? Commented Sep 20, 2013 at 22:03
  • I want that ?id=444 in motogp.php, when trying to access to /motogp.php?id=3 it gives me errors. Commented Sep 20, 2013 at 22:05
  • Then you'll want to change your links to include motogp.php. And then you'll have a lot more issues, since that page looks like your "form handler". The page you use to handle form data (the page referenced by your form's action should typically be different than the page you use to view data from the database. Commented Sep 20, 2013 at 22:08

1 Answer 1

1

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,
Sign up to request clarification or add additional context in comments.

3 Comments

So I place $id = $_GET['id']; in my motogp.php file? I really don't understand this..
You place $id= $_GET['id']; on the file which you're trying to make dynamic.
I placed it in motogp.php and if if type /motogp.php?id=1 it gives me error (Undefined index)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.