User id
-
- Posts: 8
- Joined: Thu Jul 14, 2011 5:54 pm
User id
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?
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
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
-
- Posts: 8
- Joined: Thu Jul 14, 2011 5:54 pm
Re: User id
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?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
Re: User id
Have you looked at the login tutorials ? Putting it basically, you need to add the code form that.
-
- Posts: 8
- Joined: Thu Jul 14, 2011 5:54 pm
Re: User id
In one tutorial you use $_SESSION as ID in other $_SESSION as username, thats why I don't know how to do it.jacek wrote:Have you looked at the login tutorials ? Putting it basically, you need to add the code form that.
Re: User id
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.
-
- Posts: 8
- Joined: Thu Jul 14, 2011 5:54 pm
Re: User id
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
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
=)
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
<?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
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
yes i know but is better of show the datajacek 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.
Re: User id
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.
If the code is in another tutorial, can someone post a link please thank you.
Re: User id
That depends on your code so far. When the user logs in, you need to store their user id in the session.BluePixel wrote:What files do i need to edit to have an actual user login and edit there profile?
The code you need is basically this
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.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']; } ?>
Have a go and post back if you get stuck.
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.BluePixel wrote:This is really complicated. This tutorial started off good but now it's poorly done.
Re: User id
So my int.inc.php file should look like this?jacek wrote:That depends on your code so far. When the user logs in, you need to store their user id in the session.BluePixel wrote:What files do i need to edit to have an actual user login and edit there profile?
The code you need is basically thisAlthough 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.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']; } ?>
Have a go and post back if you get stuck.
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.BluePixel wrote:This is really complicated. This tutorial started off good but now it's poorly done.
<?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
No, you should make a function to get information on the user and store the result of that in the session.BluePixel wrote:So my int.inc.php file should look like this?
You don't actually run that query.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
Re: User id
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
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
No.squerner wrote:plz jackek can you edit the code for us.
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.squerner wrote:i really dont understand this all.
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
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
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 placeBluePixel 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.
Re: User id
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.jacek wrote: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 placeBluePixel 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.
Re: User id
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.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.
Either way, you obviously don't want to get this problem solved now so this is locked.