Jump to content

[SOLVED] sending values to a script via url... help!!


chriskiely

Recommended Posts

Hello, I am new to this forum, hoping that someone out there can help me with this annoying little problem!

 

I am trying to retrieve records from my database using values passed to the script via the url, but it doesn't seem to working. Here is my code:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd ">

<html>

<head>

<title>Show Pros - The Professionals' Touring Resource</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="bluebox_style.css" rel="stylesheet" type="text/css">

 

<?php

if(isset($_GET['user'])) {

$user_name = $_GET['user'];

} else {

echo 'This page has been accessed in error'; #An error page can be made at a later date

exit();

}

require_once('../../mysql_connect.php');

$display_name_query = "SELECT display_name FROM users WHERE (user_name=$user_name)";

$display_name = @mysql_query($display_name_query);

 

mysql_close();

?>

</head>

 

<body>

user name=

<?php

  echo $user_name;

?> <br>

display name=

<?php

  if($display_name) {

  while ($row = mysql_fetch_array ($display_name)) {

    echo $row['display_name'];

  }

  } else {

  echo 'not working';

  }

?>

</body>

</html>

 

 

Which gives the output (for users.php?user=chriskiely):

 

user name= chriskiely

display name= not working

 

However, if i change the query to explicitly retrieve the record I'm after, i.e.:

 

$display_name_query = "SELECT display_name FROM users WHERE (user_name='chriskiely')";

 

I get the required output -

 

user name= chriskiely

display name= Christopher Kiely

 

I know the value is getting passed to the script from the URL as I can display $user_name, just can't see why it won't get the chriskiely record from the database.

 

Any help on this would be much appreciated.

 

Cheers,

Chris

 

well that seems to have worked, having spent hours fiddling with it yesterday, the one thing i would never have tried would have been putting it in quotes, i thought it would look for the text $user_name in the database rather than look for the string value, but there you go! thank you very much for the help :)

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.