Jump to content

Recommended Posts

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 thing
My 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.
Thanks
maxic0
Link to comment
https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/
Share on other sites

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]
<?php
if (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]
Link to comment
https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66188
Share on other sites

Try:

[code]
<?php
if (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]
Link to comment
https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66244
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/16063-_get-help-please-fixed/#findComment-66631
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.