maxic0 Posted July 31, 2006 Share Posted July 31, 2006 Hi, i haven't been doing PHP for to long, so i don't know about some thing at all. I have never quite got my head around the $_GET thingMy friend was kind enout to make this little script just to show how it works.[code]<?php$sentence = 'Hello, ' . $_GET['name'] . ', and welcome to my little page.';echo $sentence;?><br /> <br /><a href="indexx.php?name=Simon">Simon</a><br /><a href="indexx.php?name=John">John</a><br /><a href="indexx.php?name=Max">Max</a><br />[/code]This code is easy to understand, but in my site i want to create a page where the information is stored in a database and then the information is collected from there. So for example if a had a table called "people " and then a little information about Simon, John and Max was stored stored in there in a field called "info" how would i echo the information about them when their name is clicked.Any help would be very appreciated. Thanksmaxic0 Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/ Share on other sites More sharing options...
pixy Posted July 31, 2006 Share Posted July 31, 2006 1. You will always want to escape $_GET variables so that people do not enter malicious content onto your site. 2. Here's what I think you want:[code]<?phpif (isset($_GET['name'])) { $name = $_GET['name']; $query = "SELECT * FROM users WHERE name='$name'"; $result = mysql_query($result) or die(mysql_error()); if ($result) { while ($row = mysql_fetch_array($result)) { echo $row['name']; // Output all information. } } else { echo 'Error with query: '.$query.'<br>'.mysql_error(); }}else { echo 'You must specify a name.';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66188 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 Thats perfect pixy, Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66197 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 Oh no sorry, there is a small problem :-[.I get the output "Query was empty" even if there is something in the field.I changed echo $row['name']; to the names of the different rows, but i get the same thing everytime. =/Can you help me please. Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66200 Share on other sites More sharing options...
hostfreak Posted July 31, 2006 Share Posted July 31, 2006 You also changed the variable right? "$name" = $_GET['name']; ? Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66205 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 Yeah that part of it is right, but it just Says "Query was empty".I don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66208 Share on other sites More sharing options...
hostfreak Posted July 31, 2006 Share Posted July 31, 2006 Try:[code]<?phpif (isset($_GET['name'])) { $name = $_GET['name']; $query = "SELECT * FROM users WHERE name='$name'"; $result = mysql_query($result) or die(mysql_error()); if ($result) { while ($row = mysql_fetch_array($result)) { $name = $row["name"]; echo $row['name']; // Output all information. } } else { echo 'Error with query: '.$query.'<br>'.mysql_error(); }}else { echo 'You must specify a name.';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66244 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 No it still just says that the query is empty. :( Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66526 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 Please Reply. Someone must know the answer. Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66591 Share on other sites More sharing options...
maxic0 Posted July 31, 2006 Author Share Posted July 31, 2006 For the record this was the problem.This line was wrong..[code]$result = mysql_query($result) or die(mysql_error());[/code]It should be..[code]$result = mysql_query($query) or die(mysql_error());[/code]Thanks for your help everyone. :D Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66606 Share on other sites More sharing options...
kenrbnsn Posted July 31, 2006 Share Posted July 31, 2006 Change[code]<?php $result = mysql_query($result) or die(mysql_error()); ?>[/code]to[code]<?php $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); [/code]You are trying to use the contents of the variable [b]$result[/b] instead of [b][color=red]$query[/color][/b].Ken Quote Link to comment https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.