Jump to content

Connecting session numbers with a database


Seaholme

Recommended Posts

It's hard to articulate this, but basically I have this bit of PHP

 

// Get all the data from the dogs table
        $result = mysql_query("SELECT * FROM dogs
              WHERE owner='13'") or die(mysql_error());  

 

And the general set-up is that I want the owner=13 bit to have it so that instead of 13, the database selects anything which has the same 'owner' number as the session ID. Or just basically some way to show only the dogs from the database where the person who's logged into the account is also their owner, rather than every player seeing every dog.

 

I've tried the below, if it helps you to understand what I mean...

 

// Get all the data from the dogs table
        $result = mysql_query("SELECT * FROM dogs
              WHERE owner='$_SESSION['id']") or die(mysql_error());  

 

But I just get this error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/91/6351791/html/camp.php on line 16

 

Can anybody help me work out how to tie in the user session (and therefore the user's ID) with picking certain things out of the database?

 

Please let me know if anything needs explaining further!

Thanks.

 

Thanks -- that does solve the error I had before.

 

Only now it says

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2

 

I have a feeling I'm going about this the wrong way. Does anybody know I can tie a user's details and account session with the things (dogs in this case) belonging to that user, so they only see what belongs to them?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.