JuliusSecret JuliusSecret - 1 year ago 99
SQL Question

PHP/MySQL - how to add MySQL data to url in address bar without a form

I have a website at


In this file, I load a random row from my MySQL table. I have around 1000 rows, and it will randomly pick one row, and return some data from that row into my page. For example, if it chooses row 467 with:

name = George
age = 23
key = fe4v6

It will show on my
something like:
hello, George (23 years old)
. The key is a random, unique variable for each row.

What I want: I want my URL in the address bar to update automatically on refresh with the key attribute. So I want:
. When I refresh the page, I want it to update the URL with the new key value for the corresponding row in my MySQL database.

I don't work with forms. I make a connection with my database and I use queries and
on the random row. In my
I show the name like this:

<?php echo $row['name'] ?>

I don't know how easy or difficult this is, maybe there is a much easier solution. I would like to hear from you, thanks!

Answer Source

A quick solution would be to use a header redirect

if(!isset($_GET['UniqueKey'] {
    header('location: localhost:8888/documents/index.php?UniqueKey='.$row['name']);

The code firsts checks if UniqueKey is set, so it doesn't redirect infinitely.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download