#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Question 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:
     
    if (isset($_GET['view']))
    	{
    		$viewUser = sanitizeString($_GET['view']);
    		$query = "SELECT * FROM gtmembers WHERE user='$viewUser'";
    		$result = queryMysql($query);
    		if (mysql_num_rows($result))
    		{
    			<u><b>$bio = mysql_result($result,1,'text');</b></u>
    			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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Question 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.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    the row numbers start with 0, so you have to use

    PHP Code:
    mysql_result($result0'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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,496
    Rep Power
    594
    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.
    Last edited by gw1500se; November 10th, 2012 at 07:04 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    Neither user nor text are reserved in MySQL. They are deliberately exempted.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep 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!

IMN logo majestic logo threadwatch logo seochat tools logo