The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Issue with mysql result
Discuss Issue with mysql result in the PHP Development forum on Dev Shed. Issue with mysql result PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 9th, 2012, 11:22 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 7
Time spent in forums: 1 h 43 m 36 sec
Reputation Power: 0
|
|
Issue with mysql_result
Wasn't sure if to post this here or in Mysql, but since it involves a lot of php I decided to put it here.
Having an issue setting up a profile page system. More specifically with retreiving the biography or about me portion of someones profile from a database.
Heres the code:
Code Code:
Original
- Code Code |
|
|
|
if (isset($_GET['view']))
{
$viewUser = sanitizeString($_GET['view']);
$query = "SELECT * FROM gtmembers WHERE user='$viewUser'";
$result = queryMysql($query);
if (mysql_num_rows($result))
{
$bio = mysql_result($result,1,'text');
if ($viewUser == $user)
{
if ($bio == "") $bio = "No bio set. Create one now!";
echo $viewUser;
echo <<<_END
<form method='post' action='gtprofile.php?view=$user'>
<textarea name='setBio' cols='40' rows='3'>$bio</textarea><br />
<input type='hidden' name='myUser' value='$user' />
<input type='submit' value='Update' />
</form>
_END;
}
else
{
if ($bio == "") $bio = "User has not yet created their bio.";
echo $viewUser . "<br />";
echo $bio;
}
}
else echo "User does not exist.";
}
And the error:
Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 6 in C:\gtcom\gtprofile.php on line 27
And the table:
createTable('gtprofile', 'user VARCHAR(16), text VARCHAR(4096), INDEX(user(6))');
Line 27 is bold and underlined.
I've tried many variations of mysql_result (even tho its slower than fetch_array and others I only need the value of text) but still the same issue. Compared to similar code, this seems like it would work.
The code basically checks to see if the user viewing the profile is the owner, and if they are it displays a form that lets them change their profile. Otherwise, it just displays that user's profile.
Also, usernames are unique.
|

November 10th, 2012, 12:13 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 7
Time spent in forums: 1 h 43 m 36 sec
Reputation Power: 0
|
|
Issue with mysql result
Having an issue setting up a profile page system. More specifically with retreiving the biography or about me portion of someones profile from a database.
Heres the code:
PHP Code:
if (isset($_GET['view']))
{
$viewUser = sanitizeString($_GET['view']);
$query = "SELECT * FROM gtmembers WHERE user='$viewUser'";
$result = queryMysql($query);
if (mysql_num_rows($result))
{
$bio = mysql_result($result,1,'text');//This line is erroring
if ($viewUser == $user)
{
if ($bio == "") $bio = "No bio set. Create one now!";
echo $viewUser;
echo <<<_END
<form method='post' action='gtprofile.php?view=$user'>
<textarea name='setBio' cols='40' rows='3'>$bio</textarea><br />
<input type='hidden' name='myUser' value='$user' />
<input type='submit' value='Update' />
</form>
_END;
}
else
{
if ($bio == "") $bio = "User has not yet created their bio.";
echo $viewUser . "<br />";
echo $bio;
}
}
else echo "User does not exist.";
}
And the error:
Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 6 in C:\gtcom\gtprofile.php on line 27
And the table:
createTable('gtprofile', 'user VARCHAR(16), text VARCHAR(4096), INDEX(user(6))'); //a function i made to make tables
Line 27 has comment beside it
I've tried many variations of mysql_result (even tho its slower than fetch_array and others I only need the value of text) but still the same issue. Compared to similar code, this seems like it would work.
The code basically checks to see if the user viewing the profile is the owner, and if they are it displays a form that lets them change their profile. Otherwise, it just displays that user's profile.
Also, usernames are unique.
|

November 10th, 2012, 04:52 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Hi,
the row numbers start with 0, so you have to use
PHP Code:
mysql_result($result, 0, 'text')
By the way, did your really use your createTable() function? I can hardly believe that it works, because "user" and "text" are all reserved words. If you simply copy this string into a "CREATE TABLE" query, you should get all kinds of syntax errors.
|

November 10th, 2012, 07:01 AM
|
|
|
Do you really want the 2nd returned row? The rows from MySQL are zero based. If it returns only 1 row, the first and only row will be number zero. If only 1 row is returned by your query then you will get exactly the error you are seeing. Perhaps this is what you really mean:
PHP Code:
$bio = mysql_result($result,0,'text');
P.S. I suggest you not use the depreciated MySQL extensions but PDO instead. Also please enclose your PHP code in [ PHP ] tags rather than [ CODE ] tags. See ManiacDan's New User Guide.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
Last edited by gw1500se : November 10th, 2012 at 07:04 AM.
|

November 10th, 2012, 07:58 AM
|
|
|
|
Neither user nor text are reserved in MySQL. They are deliberately exempted.
|

November 10th, 2012, 12:00 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Threads merged since they had a similar title and same error message.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

November 10th, 2012, 03:07 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 7
Time spent in forums: 1 h 43 m 36 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Jacques1 Hi,
the row numbers start with 0, so you have to use
|
This worked, but now i'm getting this error:
Warning: mysql_result(): text not found in MySQL result index 6 in C:\gtcom\gtprofile.php on line 27
I changed the if bio = "" to if bio = NULL but still nothing.
|

November 10th, 2012, 03:39 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 7
Time spent in forums: 1 h 43 m 36 sec
Reputation Power: 0
|
|
Wow I'm an idiot.
The error lies here:
PHP Code:
$query = "SELECT * FROM gtmembers WHERE user='$viewUser'";
The text should say:
PHP Code:
$query = "SELECT * FROM gtprofile WHERE user='$viewUser'";
The table gtmembers stores login information and nothing else. The table should direct to gtprofile where bios, and images and such will be stored.
:facepalm:
Thanks for the help!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|