Page 1 of 1

User id

Posted: Sat Jul 16, 2011 7:36 pm
by gosponTarik
Hi, me again.

In User Profile tutorial you entered $_SESSION['uid'] = 1; in init.inc.php file.
I was wondering, how can i get that id from user_id in database. So if user with user_id = 43 login in, write his id instead of this 1?

Re: User id

Posted: Sat Jul 16, 2011 7:57 pm
by jacek
In the login tutorials I stored the user of of the logged in user in the session, this was just to simulate someone being logged in

Re: User id

Posted: Sat Jul 16, 2011 8:07 pm
by gosponTarik
jacek wrote:In the login tutorials I stored the user of of the logged in user in the session, this was just to simulate someone being logged in
I know that, i was wondering how can i instead of simulating, use session as real user is logged in? what code should I add?

Re: User id

Posted: Sat Jul 16, 2011 11:16 pm
by jacek
Have you looked at the login tutorials ? Putting it basically, you need to add the code form that.

Re: User id

Posted: Sun Jul 17, 2011 9:33 pm
by gosponTarik
jacek wrote:Have you looked at the login tutorials ? Putting it basically, you need to add the code form that.
In one tutorial you use $_SESSION as ID in other $_SESSION as username, thats why I don't know how to do it. :?

Re: User id

Posted: Mon Jul 18, 2011 9:01 am
by jacek
Oh I see ! Well you could use the username to get the user id from the database. I would probably create a new function to get the user id and some other basic information based on the username, and store the result of that in the session.

Re: User id

Posted: Mon Jul 18, 2011 5:09 pm
by gosponTarik
jacek wrote:Oh I see ! Well you could use the username to get the user id from the database. I would probably create a new function to get the user id and some other basic information based on the username, and store the result of that in the session.

Thanks, I'll try that.

Re: User id

Posted: Tue Jul 19, 2011 6:14 am
by Muhanned
hi
you can make it
hen the user is login and he is logined do like this
when your code are checked if that was login or not
save the user id in session =)
that is the best way
=)

Re: User id

Posted: Tue Jul 19, 2011 6:19 am
by Muhanned
<?php
session_start();
$sql="SELECT username,password FROM users  WHERE username='userfrom post' AND password='password  from  post  '";
while($user=mysql_fetch_assoc($sql)){
  $id=$user['id'];
  $username=$user['username'];
  $password=$user['password'];
}
if($username = $_POST['user'] && $password == $_POST['pass']){
  $_SESSION['uid']=$user['id'];
}
?>
^^
i forget this =)

Re: User id

Posted: Tue Jul 19, 2011 2:26 pm
by jacek
That idea is exactly right, but there code has a few problems. There is no need for a while loop when only selecting one row, and that query should really go in a function.

Re: User id

Posted: Tue Jul 19, 2011 7:53 pm
by Muhanned
jacek wrote:That idea is exactly right, but there code has a few problems. There is no need for a while loop when only selecting one row, and that query should really go in a function.
yes i know but is better of show the data :)

Re: User id

Posted: Tue Jul 19, 2011 8:16 pm
by BluePixel
This is really complicated. This tutorial started off good but now it's poorly done. What files do i need to edit to have an actual user login and edit there profile? Which lines of code need to be altered?

If the code is in another tutorial, can someone post a link please thank you.

Re: User id

Posted: Wed Jul 20, 2011 3:11 pm
by jacek
BluePixel wrote:What files do i need to edit to have an actual user login and edit there profile?
That depends on your code so far. When the user logs in, you need to store their user id in the session.

The code you need is basically this
Muhanned wrote:
<?php
session_start();
$sql="SELECT username,password FROM users  WHERE username='userfrom post' AND password='password  from  post  '";
while($user=mysql_fetch_assoc($sql)){
  $id=$user['id'];
  $username=$user['username'];
  $password=$user['password'];
}
if($username = $_POST['user'] && $password == $_POST['pass']){
  $_SESSION['uid']=$user['id'];
}
?>
Although it should be done with a function, you could even make the valid_credentials() function from the login system (http://www.youtube.com/view_play_list?p ... A12314F07E) return the users id if they exist instead of true which could remove an extra query.

Have a go and post back if you get stuck.
BluePixel wrote:This is really complicated. This tutorial started off good but now it's poorly done.
The tutorial does not deal with making users edit their own profiles if that’s what you mean, I think I mentioned that the manual setting of $_SESSION['uid'] is just to simulate a user being logged in and you should use the logged in users id for this.

Re: User id

Posted: Sun Jul 24, 2011 8:58 am
by BluePixel
jacek wrote:
BluePixel wrote:What files do i need to edit to have an actual user login and edit there profile?
That depends on your code so far. When the user logs in, you need to store their user id in the session.

The code you need is basically this
Muhanned wrote:
<?php
session_start();
$sql="SELECT username,password FROM users  WHERE username='userfrom post' AND password='password  from  post  '";
while($user=mysql_fetch_assoc($sql)){
  $id=$user['id'];
  $username=$user['username'];
  $password=$user['password'];
}
if($username = $_POST['user'] && $password == $_POST['pass']){
  $_SESSION['uid']=$user['id'];
}
?>
Although it should be done with a function, you could even make the valid_credentials() function from the login system (http://www.youtube.com/view_play_list?p ... A12314F07E) return the users id if they exist instead of true which could remove an extra query.

Have a go and post back if you get stuck.
BluePixel wrote:This is really complicated. This tutorial started off good but now it's poorly done.
The tutorial does not deal with making users edit their own profiles if that’s what you mean, I think I mentioned that the manual setting of $_SESSION['uid'] is just to simulate a user being logged in and you should use the logged in users id for this.
So my int.inc.php file should look like this?
<?php

session_start();

$sql="SELECT username, pwd FROM users  WHERE username='user from post' AND pwd='password  from  post  '";
while($user=mysql_fetch_assoc($sql)){
  $id=$user['id'];
  $username=$user['username'];
  $password=$user['pwd'];
}
if($username = $_POST['user'] && $password == $_POST['pwd']){
  $_SESSION['uid']=$user['id'];
}

mysql_connect('*************', '******', '******');
mysql_select_db('*******');


$path = dirname(__FILE__);

include("{$path}/inc/user.inc.php");



?>
I'm getting this error.

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/13/6987913/html/tutorials/user_profiles/core/init.inc.php on line 6

Re: User id

Posted: Sun Jul 24, 2011 10:30 am
by jacek
BluePixel wrote:So my int.inc.php file should look like this?
No, you should make a function to get information on the user and store the result of that in the session.
BluePixel wrote:I'm getting this error.

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/13/6987913/html/tutorials/user_profiles/core/init.inc.php on line 6
You don't actually run that query.

Re: User id

Posted: Sun Jul 24, 2011 12:18 pm
by squerner
i really dont understand this all.
plz jackek can you edit the code for us.
i will give you everything you want plzz.
i need it so much i want to launch my site soon and i tried much thing but nothing works plzz

Re: User id

Posted: Mon Jul 25, 2011 11:23 am
by jacek
squerner wrote:plz jackek can you edit the code for us.
No.
squerner wrote:i really dont understand this all.
You need to get the user id that corresponds to the username that they logged in with. Start by making a function that gets the user id form the database for the username that you give it.
function fetch_user_id($username){
    $username = mysql_real_escape_string($username);
    
    $sql = "";
    
    $result = mysql_query($sql);
    
    return mysql_result($result, 0);
}
Would be a starting point.

Re: User id

Posted: Sun Jul 31, 2011 7:46 pm
by BluePixel
Pointless tutorial. I have a programmer that'll do this for me for 75.00. I don't have the time to try and complete have finished tutorials.

Re: User id

Posted: Sun Jul 31, 2011 8:34 pm
by jacek
BluePixel wrote:Pointless tutorial. I have a programmer that'll do this for me for 75.00. I don't have the time to try and complete have finished tutorials.
The point of the tutorials and this forum is that you should in theory learn something. If you just want to get somethign working you are in the wrong place ;)

Re: User id

Posted: Thu Aug 04, 2011 10:47 pm
by BluePixel
jacek wrote:
BluePixel wrote:Pointless tutorial. I have a programmer that'll do this for me for 75.00. I don't have the time to try and complete have finished tutorials.
The point of the tutorials and this forum is that you should in theory learn something. If you just want to get somethign working you are in the wrong place ;)
you learn by asking questions, and doing tutorials, which I just did. Your tutorial doesn't show how to apply this technique to real world applications therefore it is pointless.

Re: User id

Posted: Fri Aug 05, 2011 1:30 pm
by jacek
BluePixel wrote:you learn by asking questions, and doing tutorials, which I just did. Your tutorial doesn't show how to apply this technique to real world applications therefore it is pointless.
I explained in the video that I did not want to overcomplicate things by also making a login system, I would not say this makes it pointless though. If you just want to get a working profile system then a tutorial is not really the place to get it, for that you would be better off buying somethign or hiring a developer, the point of the tutorial is to explain the basics of the profile system which I am pretty sure I did.

Either way, you obviously don't want to get this problem solved now so this is locked.