chriskiely Posted May 5, 2007 Share Posted May 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/50113-solved-sending-values-to-a-script-via-url-help/ Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 $display_name_query = "SELECT display_name FROM users WHERE user_name='$user_name'"; Link to comment https://forums.phpfreaks.com/topic/50113-solved-sending-values-to-a-script-via-url-help/#findComment-246050 Share on other sites More sharing options...
chriskiely Posted May 5, 2007 Author Share Posted May 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/50113-solved-sending-values-to-a-script-via-url-help/#findComment-246055 Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 u r welcome. Link to comment https://forums.phpfreaks.com/topic/50113-solved-sending-values-to-a-script-via-url-help/#findComment-246058 Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 Please mark the post as solved. Link to comment https://forums.phpfreaks.com/topic/50113-solved-sending-values-to-a-script-via-url-help/#findComment-246062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.