User id

Post here is you are having problems with any of the tutorials.
Locked
gosponTarik
Posts: 8
Joined: Thu Jul 14, 2011 5:54 pm

User id

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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
Image
gosponTarik
Posts: 8
Joined: Thu Jul 14, 2011 5:54 pm

Re: User id

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post by jacek »

Have you looked at the login tutorials ? Putting it basically, you need to add the code form that.
Image
gosponTarik
Posts: 8
Joined: Thu Jul 14, 2011 5:54 pm

Re: User id

Post 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. :?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
gosponTarik
Posts: 8
Joined: Thu Jul 14, 2011 5:54 pm

Re: User id

Post 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.
Muhanned
Posts: 7
Joined: Mon May 16, 2011 6:16 pm

Re: User id

Post 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
=)
Muhanned
Posts: 7
Joined: Mon May 16, 2011 6:16 pm

Re: User id

Post 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 =)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
Muhanned
Posts: 7
Joined: Mon May 16, 2011 6:16 pm

Re: User id

Post 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 :)
BluePixel
Posts: 7
Joined: Tue Jul 19, 2011 9:18 am

Re: User id

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
BluePixel
Posts: 7
Joined: Tue Jul 19, 2011 9:18 am

Re: User id

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
squerner
Posts: 2
Joined: Sat Jul 23, 2011 4:06 pm

Re: User id

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
BluePixel
Posts: 7
Joined: Tue Jul 19, 2011 9:18 am

Re: User id

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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 ;)
Image
BluePixel
Posts: 7
Joined: Tue Jul 19, 2011 9:18 am

Re: User id

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User id

Post 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.
Image
Locked