rallokkcaz Posted April 28, 2007 Share Posted April 28, 2007 i have a user system, and i am currently working on a update page for the user i have the whole system down its just that for it too work i have to put in the id in $sql and i can't set it as a variable because it doesn't get a number is there somekind of way that i can get id through a session? because thats the only way it would work thanks guys Link to comment https://forums.phpfreaks.com/topic/49026-how-to-find-id-in-database/ Share on other sites More sharing options...
AndyB Posted April 28, 2007 Share Posted April 28, 2007 Unfortunately, that's less than fully comprehensible. You can update a record as long as you have a WHERE some_field = 'some_value'. i.e. the SQL engine can find the record you want to update. Otherwise ... So does your database contain an id field or not? Link to comment https://forums.phpfreaks.com/topic/49026-how-to-find-id-in-database/#findComment-240193 Share on other sites More sharing options...
rallokkcaz Posted April 28, 2007 Author Share Posted April 28, 2007 it does its just i can't figure out how to make a variable that gets the users current logged in id Link to comment https://forums.phpfreaks.com/topic/49026-how-to-find-id-in-database/#findComment-240195 Share on other sites More sharing options...
Silverado_NL Posted April 28, 2007 Share Posted April 28, 2007 title = how to find id in database ??? .... i have to put in the id in $sql ???? please be more clear with your questions. do the users already have an id number??? if not create an ID column (TYPE = INT)in your member table and put it on auto_increment now it will automaticly generate an id number everytime a new member is created. if they already have id numbers then you can set a session variable (that will contain the id)in the login script. something like this $query = mysql_query("SELECT ID FROM members WHERE loginname = $_POST['loginname'] "); $memberinfo = mysql_fetch_array($query); $member_id = $memberinfo["ID"]; $_SESSION["member_id"] = $memberinfo["ID"]; this is how to set a normal variable $member_id = $memberinfo["ID"]; this is how to set a session variable $_SESSION["member_id"] = $memberinfo["ID"]; hope this helps you. greetz Silverado Link to comment https://forums.phpfreaks.com/topic/49026-how-to-find-id-in-database/#findComment-240199 Share on other sites More sharing options...
RyanSF07 Posted April 28, 2007 Share Posted April 28, 2007 Hi rallokkcaz, Maybe try this: On your "login processor" page - the page that actually inserts a new user's data into the database, try adding this after the INSERT code: //get user id of user just entered $user_id = mysql_insert_id(); //get user name of user (from FORM) $name = "$_POST[user_name]"; //start session session_start(); header("Cache-control: private"); //IE 6 Fix //Register session key with the value $_SESSION[id] = $user_id; $_SESSION[name] = $name; And, on your login page, try adding this after your SELECT sql: //start session session_start(); header("Cache-control: private"); //IE 6 Fix //Register session key with the value $_SESSION[id] = $row[id]; $_SESSION[name] = "$row[user_name]"; Now, not only has your user's id been inserted/selected from the database, but each time he or she logs in, it will be remembered as a session key (or whatever they're called) You can pass session keys from page to page so long as you start each php page with the following (with no spaces inbetween) <?php session_start(); So, on your EDIT page, if it begins with the above, that page should "know" the id of the user that logged in. Link to comment https://forums.phpfreaks.com/topic/49026-how-to-find-id-in-database/#findComment-240292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.