Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 6 of 6

Thread: PHP Coding Help

  1. #1
    Pen
    Pen is offline
    Enthusiast

    Join Date
    Mar 2009
    Posts
    1,282

    PHP Coding Help

    Okay, so I'm working on a site for my friend whose into VLogging, Blogging, (Comedian) etc. So, I need help with some php coding I'm working on. Here's the error I'm getting.
    Code:
    <?php
    	ob_start();
    	session_start();
    	include ('global.php');
    	
    	$session_username = $_SESSION['username'];
    	$android = "Android";
    	$user = mysql_query("SELECT * FROM users WHERE $session_username='username'");
    	while ($row = mysql_fetch_assoc($user));
    	{
    	$password = $row['passowrd'];
    	$username = $row['username'];
    	$email = $row['email'];
    	}
    	
    	
    	if ($session_username == $android)
    	{
    		include ('include/andrew_ucp.php');
    	}
    	elseif ($session_username == $username)
    	{
    		 $id = $row['id'];
    		 echo $id;
    	}
    	else
    	{
    		?><html><meta http-equiv="refresh" content="0;URL=index.php"></html><?php
    
    	}
    	
    	 
    ?>
    Here's the error I'm getting.
    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\androids\ucp.php on line 9

    Thanks in advanced!
    Also, I'd like to keep this open after I get some help for future questions.

  2. #2
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: PHP Coding Help

    You're getting that error because your query is failing.

    Directly after your mysql query run;

    echo mysql_error();

    This will provide you with more explicit error messages.

    Right from the get go it doesn't look right to me. Should be in the format of -

    Code:
       $user = mysql_query("SELECT * FROM users WHERE Column/field-NAME='VALUE'");
    I think you have it the other way around.

    Also you have output buffering turned on, but you don't appear to be using it?

  3. #3
    Pen
    Pen is offline
    Enthusiast

    Join Date
    Mar 2009
    Posts
    1,282

    Re: PHP Coding Help

    Hmmm. Well, when I plug in the code I have already to the actual website (The previous post was from xampp) I don't get a error message, rather I get this. "Unknown column 'Justin' in 'where clause' ".

    But, I get this when in Xampp, "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\androids\ucp.php on line 10"

    Here's the code its specifically talking about:
    Code:
    while ($row = mysql_fetch_assoc($user))

  4. #4
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: PHP Coding Help

    Read my first post again.

    I've pointed out your problem.

    Your query is incorrect, you've got the column and value the wrong way around.

    You've just proved it;

    Code:
    "Unknown column 'Justin' in 'where clause' ".

  5. #5
    lucien is queen Hazzystan's Avatar

    Join Date
    Feb 2008
    Location
    Scotland
    Posts
    2,977

    Re: PHP Coding Help

    In other words is should be
    Code:
    $user = mysql_query("SELECT * FROM users WHERE username='$session_username'");
    Not this
    Code:
    $user = mysql_query("SELECT * FROM users WHERE $session_username='username'");
    You have your variable and your column name the wrong way round, as Adam said.
    what is homo love?

  6. #6
    Pen
    Pen is offline
    Enthusiast

    Join Date
    Mar 2009
    Posts
    1,282

    Re: PHP Coding Help

    Ah, ok. Thank you very much guys!


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •