Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Viewing Profile in PHP  (Read 1332 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
Viewing Profile in PHP
« on: May 14, 2007, 01:05:04 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\black_site\profile.php on line 5

whenever i use this script:
Code: [Select]
<? include $_SERVER['DOCUMENT_ROOT']."/black_site/layout/top.php"; ?>
<?
$user = $_GET['username'];
$query = mysql_query("SELECT `id`, `username`, `email`, `class`, `msn`, `icq`, `yaim`, `site`, `site_name`, `age`, `date_born`, `interests`, `ocupation`, `postition` FROM user_pro WHERE username='$user");
while ($row = mysql_fetch_array($query)) {
?>
<table border="1" width="500">
<tr>
<td width="250">
MSN: <? print $msn; ?>
</td>
<td width="250">
ICQ: <? print $icq; ?>
</td>
</tr>
<tr>
<td width="250">
Yahoo IM: <? print $row['yaim']; ?>
</td>
<td width="250">
Website: <a href="<? print $row['site']; ?>"><? print $row['site_name']; ?></a>
</td>
</tr>
<tr>
<td width="250">
Age: <? print $row['age']; ?>
</td>
<td width="250">
Date of Birth: <? print $row['dob']; ?>
</td>
</tr>
<tr>
<td width="250">
Ocupation: <? print $row['ocupation']; ?>
</td>
<td width="250">
Interests:<br />
<? print $row['interests']; ?>
</td>
</tr>
</table>
<?
}
include $_SERVER['DOCUMENT_ROOT']."/black_site/layout/bottum.php"; ?>
does anyone know whats wrong?
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: Viewing Profile in PHP
« Reply #1 on: May 14, 2007, 11:41:29 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Check your query, that error almost always appears when your query has failed.
Logged
Re: Viewing Profile in PHP
« Reply #2 on: May 14, 2007, 03:30:18 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
Code: [Select]
WHERE username='$useri'm sure you can see what's wrong there
Logged

PoeFacedKilla

Prussian Killer Bee
Re: Viewing Profile in PHP
« Reply #3 on: May 14, 2007, 08:59:28 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Code: [Select]
WHERE username='$useri'm sure you can see what's wrong there
yeah i fixed that, but i still get the same error
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: Viewing Profile in PHP
« Reply #4 on: May 14, 2007, 09:00:57 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1645
change
Code: [Select]
$query = mysql_query("SELECT `id`, `username`, `email`, `class`, `msn`, `icq`, `yaim`, `site`, `site_name`, `age`, `date_born`, `interests`, `ocupation`, `postition` FROM user_pro WHERE username='$user");into
Code: [Select]
$query = mysql_query("SELECT * FROM user_pro WHERE username='$user'");you forgot a ' single quote and also selecting * (wildcard) works smoother.

Edit: whow you´re fast XD you posted just before I posted this, anyways, what´s the error exactly?
Logged
  • Virtual Security

PoeFacedKilla

Prussian Killer Bee
Re: Viewing Profile in PHP
« Reply #5 on: May 14, 2007, 09:08:03 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
the error is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\black_site\profile.php on line 5
but i've corrected the script:
Code: [Select]
<? include $_SERVER['DOCUMENT_ROOT']."/black_site/layout/top.php"; ?>
<?
$user = $_GET['user'];
$query = mysql_query("SELECT * FROM users_pro WHERE name='$user'");
while ($row = mysql_fetch_array($query)) {
?>
<table border="1" width="500">
<tr>
<td width="250">
MSN: <? print $row['msn']; ?>
</td>
<td width="250">
ICQ: <? print $row['icq']; ?>
</td>
</tr>
<tr>
<td width="250">
Yahoo IM: <? print $row['yaim']; ?>
</td>
<td width="250">
Website: <a href="<? print $row['site']; ?>"><? print $row['site_name']; ?></a>
</td>
</tr>
<tr>
<td width="250">
Age: <? print $row['age']; ?>
</td>
<td width="250">
Date of Birth: <? print $row['date_born']; ?>
</td>
</tr>
<tr>
<td width="250">
Ocupation: <? print $row['class']; ?>
</td>
<td width="250">
Interests:<br />
<? print $row['position']; ?>
</td>
</tr>
</table>
<?
}
include $_SERVER['DOCUMENT_ROOT']."/black_site/layout/bottum.php"; ?>
and i still get the same error
« Last Edit: May 14, 2007, 09:10:06 pm by linkthemaster »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

Lady Krisiries

Re: Viewing Profile in PHP
« Reply #6 on: May 15, 2007, 04:19:02 pm »
As I said in the post you posted a bit ago, you need to seperate the variables from the string using {$user}, etc. It's invalidating your MySQL Query. You should add code to check for MySQL errors in the future, it isn't hard.
Logged

PoeFacedKilla

Prussian Killer Bee
Re: Viewing Profile in PHP
« Reply #7 on: May 15, 2007, 10:45:53 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
i prefer the way i was coding it to {$user}, but i've figured it out, as ive said i was just brain dead there for an hour or two.
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: Viewing Profile in PHP
« Reply #8 on: May 17, 2007, 05:51:58 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1645
change
Code: [Select]
while ($row = mysql_fetch_array($query)) {
into
Code: [Select]
while ($row = mysql_fetch_assoc($query)) {
If this won't work it depends on your MySQL version
Logged
  • Virtual Security
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.044 seconds with 55 queries.

anything