0

i have this code which is not seeming to work, what i want to do is make a query to understand users' level, and then based on that level i need to print different content, for the moment it prints the default one, and i get this error message:

mysql_result() expects parameter 1 to be resource, boolean given on this line:

$rank = mysql_result($rank1, 0, 'rank');

the code is like this:

session_start();
if(!$_SESSION['username']){

header("location:login.php"); // Redirect to login.php page
}
else //Continue to current page
header( 'Content-Type: text/html; charset=utf-8' );
$rank1 = mysql_query("SELET access FROM tbl_galleries WHERE column='username" . mysql_real_escape_string($_SESSION['username']) . "'");
$rank = mysql_result($rank1, 0, 'rank');

switch ($rank)
{
case 3:
  echo "<div><a href='#'>Order DIAMOND Membership</a></div>";
  break;

case 2:
  echo "<div><a href='#'>Order PLATINUM Membership</a></div>
    <div><a href='#'>Order DIAMOND Membership</a></div>";
  break;

case 1:
  echo "<div><a href='#'>Order ELITE Membership</a></div>
    <div><a href='#'>Order PLATINUM Membership</a></div>
    <div><a href='#'>Order DIAMOND Membership</a></div>";
  break;

default:
  echo "<div><a href='#'>Order PRO Membership</a></div>
    <div><a href='#'>Order ELITE Membership</a></div>
    <div><a href='#'>Order PLATINUM Membership</a></div>
    <div><a href='#'>Order DIAMOND Membership</a></div>";
}
1
  • there is also the typo 'SELET' in stead of 'SELECT' Commented Aug 27, 2012 at 12:09

6 Answers 6

2

you have a syntax error, SELET must be SELECT:

mysql_query("SELECT..
Sign up to request clarification or add additional context in comments.

Comments

0

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

This means you have some error in your query. Try to finalize the query in phpMyAdmin or some other such tool. Your query should go something like this

$userName = mysql_real_escape_string($_SESSION['username']);
$sql = "SELECT access 
        FROM tbl_galleries 
        WHERE username = $userName";
$result = mysql_query($sql);
$rank = mysql_result($result, 0, 'access');

Comments

0

Do you have a Mysql connection configured. You should have something like that: $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

Comments

0

Why not try this:

$username = mysql_real_escape_string($_SESSION['username']);
$rank1 = mysql_query("SELECT access FROM tbl_galleries WHERE username = '$username'");

Comments

0

You are mismatching your quotes in the query and using improper syntax:

WHERE column='username" 

Try using:

mysql_query("SELECT access FROM tbl_galleries WHERE username ='" . mysql_real_escape_string($_SESSION['username']) . "'");

Okay, tricky syntax:

$rank1 = mysql_query("SELECT access FROM tbl_galleries WHERE username" . mysql_real_escape_string($_SESSION['username']) . "'");
$rank = mysql_result($rank1, 0, 'rank');

You are using optional params to get a particular column back in the mysql_result but it does not match the column name you are selecting in your query statement;

$rank1 = mysql_query("SELECT access FROM tbl_galleries WHERE username" . mysql_real_escape_string($_SESSION['username']) . "'");
$rank = mysql_result($rank1, 0, 'access');

4 Comments

thanks for replying me :) Yes, i already did this now.. but it seems the problem is not here, i still get the same message error..
@Alb mgraph also spotted a gem of a syntax error in the mispelling of select. Was that the issue?
@Alb See edit. You are mismatching your select column name and your result column name.
Thank you.. yes, i had an error there, i fixed everything now :) thanks!
0

In your mysql query u are retrieving the only single column named access from your table and in your further code in mysql_result() function you are passing the third parameter field name as rank but in your query returned result the column or field name rank is not coming . Like this

SELECT access FROM tbl_galleries WHERE username = '$username'
$rank = mysql_result($rank1, 0, 'rank');

If you want to get result of rank field then either retrieve the rank field with the field access or retrieve all columns of your table or pass the third parameter in mysql_result function as 'access'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.