Jump to content

$_GET Question


smithmr8

Recommended Posts

Hello Again,

I am trying to get this script to show a specific person's details, ie Username, when their ID is put at the end of a URL. E.g.

Lets say someone with ID:3 has the username "Fred".

 

When the page, view.php?id=3 is shown, it should echo that username, 'Fred'.

 

I've tried to do it, but cant seen to remember how to use the id used in the url and assign it to a variable.

This is what I've got so far, which isn't working.

 

<?php include('header.php') ?>
<?php
if($_GET['id'] == $id){
$information="SELECT * FROM users WHERE ID = $id";
$result_information = mysql_query($information);
$view=mysql_fetch_array($result_information);

echo $view['username'];
} else {
echo "Error";
echo $id;
}


?>
<?php include('footer.php') ?>

Link to comment
https://forums.phpfreaks.com/topic/91582-_get-question/
Share on other sites

Oh, right. I've tried that, but it doesn't seem to be working. I cant give any error details as my host doesn't have them enabled for some reason. I now have this..

if (isset($_GET['id'] && is_numeric($_GET['id'])) {
  $id = $_GET['id'];
$information="SELECT * FROM users WHERE ID = $id";
$result_information = mysql_query($information);
$view=mysql_fetch_array($result_information);

echo $view['username'];
} else {
echo "Error";
echo $id;
}

Link to comment
https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469107
Share on other sites

try this

 

<?php 
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
$information="SELECT * FROM users WHERE ID = $id";
$result_information = mysql_query($information);
$view=mysql_fetch_assoc($result_information);
echo $view['username'];
} else {
echo "Error";
echo $id;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469118
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.