Jump to content

problem with $id


Hooch

Recommended Posts

Hey there everyone. I am trying to connect to my existing phpbb database from my main webpage. I had a usersytem set up and working, but my id in the old database was named just that, "id". But phpbb names it's id "user_id". My problem is I'm not sure what I need to change here.

// get users id$getid = "SELECT * FROM my_table WHERE username='".$user."' LIMIT 1";$getidexec = mysql_query($getid);while($r=mysql_fetch_array($getidexec)){$id = $r[id];}// set a cookiesetcookie( "id", "$id", time()+3600, "/", "", 0 );

Here's what I changed it to..

// get users id$getid = "SELECT * FROM my_table WHERE username='".$user."' LIMIT 1";$getidexec = mysql_query($getid);while($r=mysql_fetch_array($getidexec)){$id = $r[user_id];}// set a cookiesetcookie( "id", "$user_id", time()+3600, "/", "", 0 );

If this is correct, I can move on to other solutions. Thank you..Hooch

Link to comment
Share on other sites

I think you want something more like this:

// get users id$getid = "SELECT id FROM my_table WHERE username='" . mysql_real_escape_string($user) . "' LIMIT 1";$getidexec = mysql_query($getid);if ($r=mysql_fetch_assoc($getidexec)){  $id = $r['id'];}// set a cookiesetcookie( "id", $id, time()+3600, "/", "", 0 );

But for setting the cookie, look at the login section for phpBB and see how they set their cookie, then copy that and insert your own data. But you have to make sure the user with the same id also exists in the phpBB user table, because that is where phpBB will look.

Link to comment
Share on other sites

You only need to use the identifier user_id if you are working with the phpbb users table. If your table has a column name called user, or id, then you can use whatever you want. You only need to call it user_id if it's the phpbb table you are working with. In my example above, it was looking up the user in your own table, and storing that data in a cookie. You will need to make sure that the cookie names are the same, which is why I said to look at how phpbb sets the cookie and use that as a starting point.

Link to comment
Share on other sites

Sorry for the confusion, (and I'm not trying to be smart here)but in my 1st post I said I was connecting to the existing phpbb forum. So I need to have that user_id somewhere correct? I want the members of the forums to log into the main page with the forum settings. This way they do not need to create 2 accounts. I have a knack for asking confusing questions.:) I hope you understand now.

Link to comment
Share on other sites

If all you want to do is have them log into phpbb on your own page, then copy the parts of the phpbb login page that you need and put them in your own page. If you want to have accounts other than the phpbb forum, like for your website, where when the people go to the forum they are already logged in, then you will want to give them a phpbb cookie when they log in on your site, and then they will be logged in when they go to the forum. So in addition to your own cookie or session info, you will want to see how phpbb does it and do the same thing, in addition to your own stuff.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...