5 Replies - 244 Views - Last Post: 13 July 2013 - 10:38 AM Rate Topic: -----

#1 mathiaskruse  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 10-July 13

View_Profile & problems with links

Posted 13 July 2013 - 07:50 AM

Hello everyone. Once again I've run into problems during my PHP.

Anyhow, here's the deal:


I'm trying to do this, but it won't let me get my users information for my database. The purpose of this code is to display a profile page to a user.
$query = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_GET['name'])."'";


Here is the complete page:

<?php
include_once 'connect.php';

$query = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_GET['name'])."'";

$result = mysql_query($query);

$num=mysql_numrows($result);


$i=0;

while ($i < $num) {


$name = mysql_result($result,$i,"name");
$id = mysql_result($result,$i,"id");
$money = mysql_result($result,$i,"money");
$health = mysql_result($result,$i,"health");
$points = mysql_result($result,$i,"points");
$mail = mysql_result($result,$i,"mail");
$rank = mysql_result($result,$i,"rank");
$exp = mysql_result($result,$i,"exp");
$lastactive = mysql_result($result,$i,"lastactive");

$i++;


echo "<br>Name: " . $name . "<br>  Money: " . $money . "<br>  Health: " . $health . "<br> Points: " . $points . "<br> E-mail: " . $mail . "<br> Rank: " . $rank . "<br> Exp: " . $exp . "<br> Last Active: " . $lastactive . "";



}

echo "<br><br><a href='game.php'>Go Back</a><br>";


?>


Also, i'd like to make a link to this profile page at the "game"-page, i mean in a menu where you press "View Profile" and then you see your own profile.

I think it has to be something like:

View_Profile.php?<?php echo $users->name; ?>


But it guess I'm wrong since all I get is errors, and this is the link it returns:

http://localhost/View_Profile.php?%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20users%20in%20%3Cb%3EC:\xampp\htdocs\game.php%3C/b%3E%20on%20line%20%3Cb%3E61%3C/b%3E%3Cbr%20/%3E%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Trying%20to%20get%20property%20of%20non-object%20in%20%3Cb%3EC:\xampp\htdocs\game.php%3C/b%3E%20on%20line%20%3Cb%3E61%3C/b%3E%3Cbr%20/%3E



Hope that someone can help me out somehow, Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: View_Profile & problems with links

#2 mathiaskruse  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 10-July 13

Re: View_Profile & problems with links

Posted 13 July 2013 - 08:13 AM

<html>
<head>
	<link href="css/layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">

<table>
<tr><br> Name: <?php" . $name . "?></tr>
<tr><br> Money: " . $money . "</tr>
<tr><br> Health: " . $health . "</tr>
<tr><br> Points: " . $points . "</tr>
<tr><br> E-mail: " . $mail . "</tr>
<tr><br> Rank: " . $rank . "</tr>
<tr><br> Exp: " . $exp . "</tr>
<tr><br> Last Active: " . $lastactive . "</tr>
</table>

</div>
</body>
</html>

I'm also having a problem here while trying to return the $name in my HTML.

If i try and return it outside the HTML (echoing inside PHP) it works fine..

How come ?

$name = mysql_result($result,$i,"name");

my PHP for the name.

Figured the last part :D/>

I needed:

<?php echo $name; ?>

This post has been edited by andrewsw: 13 July 2013 - 08:23 AM
Reason for edit:: Fixed code tags

Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,151
  • Joined: 08-August 08

Re: View_Profile & problems with links

Posted 13 July 2013 - 08:22 AM

I try not to support deprecated, insecure code. Here's a link to help you replace yours.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: View_Profile & problems with links

Posted 13 July 2013 - 08:25 AM

This

<tr><br> Name: <?php" . $name . "?></tr>

should be

<tr><br> Name: <?php echo $name; ?></tr>

All the other values need to follow a similar pattern.

I'm assuming that all this HTML is not embedded in a single PHP echo-statement? (It cannot be because the quotes for the css would break this satement.)

This post has been edited by andrewsw: 13 July 2013 - 08:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3361
  • View blog
  • Posts: 11,398
  • Joined: 12-December 12

Re: View_Profile & problems with links

Posted 13 July 2013 - 08:32 AM

This:

View_Profile.php?<?php echo $users->name; ?>

could be correct but you need to urlencode the querystring - the $users->name.

However, you don't have a $users array(?) as indicated by the embedded error message.
Was This Post Helpful? 0
  • +
  • -

#6 mathiaskruse  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 10-July 13

Re: View_Profile & problems with links

Posted 13 July 2013 - 10:38 AM

You know what? All of my current problems are fixed! :D

Thanks alot everyone :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1