Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About storing a variable into SESSION

Status
Not open for further replies.

newlearner2005

Programmer
May 9, 2005
32
0
0
US
Hello All,

I would appreciate if anybody can help me about this.
Here is the problem:
I have "registration" database, I created a "user_info" table very simply as follow

CREATE TABLE user_info (
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
userId int(10) NOT NULL,
PRIMARY KEY (userId)
);

I created a "upload" table as follow:
CREATE TABLE upload (
id int NOT NULL auto_increment,
postId int NOT NULL default '0',
name_of_file varchar(30) NOT NULL,
type_of_file varchar(30) NOT NULL,
size_of_file int NOT NULL,
content_of_file MEDIUMBLOB NOT NULL,
PRIMARY KEY (id)
);
My question is how to pass userId from "user_info" table and assign it to postId of "upload" table?
Somebody told me I need two steps:
1- Store userId in SESSION['userId'], but I did not know how ? Please show me ? One or two lines of yours is very useful to help me instead of I waisted a lot of times to figure it out. ( I did but I still did not know)
2- Use Query Insert that "userId" into "postId" of "upload" table.
Thank tyou very much in advance.
newlearner2005
 
Hi,

You don't need a session but anyway here's what you want.

1 - $_SESSION["userid"] = "var content";
That's how you store to a session. Then calling that session var would be echo $_SESSION["userid"]

Your order of operations is simple:

$sql = // do your select call using sql

while ($result = mysql_fetch_array($sql))
{
$SESSION["userid"] = $result["userid"];
}

$sql = // do your insert/update call using sql and the $_SESSION["userid"] variable for postId part in upload table.

That's it.

Hope this helps!

NATE


mainframe.gif


Got a question? Search G O O G L E first.
 
Thank you so very much, SPYDERIX

Here are what I did. Correct me where I was wrong.

if(isset($_POST['upload']))
{
// We need the author of the uploaded file. Who has uploaded file? So I created a userId for each person.
$sql = "SELECT userId FROM user_info";
$result = mysql_query($sql) or die (mysql_error() . "<br>" .$sql);

while($result = mysql_fetch_array($sql))
{
$_SESSION['userId'] = $result['userId'];
}
$author_Id = $_SESSION['userId'];
//.....
//....
//.....
// continue here
$query = "INSERT INTO upload (postId, name, size, type, content ) ".
"VALUES ('$author_Id', '$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');

Why I was still wrong ?
Could you help me figure it out where I got wrong ?
Thank you very much.
new learner 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top