Problem of inserting from two different tables

Links for php scripts

Moderators: macek, egami, gesf

sansoft
New php-forum User
New php-forum User
Posts: 44
Joined: Fri May 07, 2004 2:16 am
Location: India
Contact:

Problem of inserting from two different tables

Postby sansoft » Fri May 14, 2004 1:46 am

Hi all,

i have a normal login form where the common users and the admin can log thru......now when the common user logs in he is presented with his assigned project details and also he can enter his "days work" like start time ,end time,daystask comments thru that.htese three details get entered in the "MAST_PROJECTTASK" table.

this table has three other fields like....user_id,proj_id ..these two fields are taken from "MAST_USER" and"MAST_PROJECT" tables respectively.

now what i want is........

when a particular user logs in thru the loginform his details shud go and enter in the third table ie "MAST_PROJECTTASK"ie

his user_id,proj_id from the first two tables shud go in the third table......

as far as my tries are concerned i used the command as

$sql="insert into mast_projecttask(user_id,proj_id)select mast_user.user_id,mast_project.proj_id from mast_user,mast_project where mast_project.proj_leadid=mast_user.user_id";

$result=mysql_query($sql,$conn);


but the thing happens is when anyone user submits his details......his along with "other users" gets entered......in the table.......ie say there r 20 users then when a particular user with user_id as 1 enters thru then all other user_ids from 2 to 20 gets entered.........which i dont want....

plz help me........

Sansoft

Alex
New php-forum User
New php-forum User
Posts: 180
Joined: Fri Mar 07, 2003 4:59 pm
Contact:

Postby Alex » Fri May 14, 2004 4:05 am

Ok if you mean what i think you mean, and i think you mean that you have a form for users to insert data into, but you only want the data to be entered into the database if the user has some kind of privileges.
In that case you would need to have 2 queries instead of one: one that will check if the user has ceratin privileges, and second one inserting the values into the database...
model:

Code: Select all

$query=("select user_privileges where userid='$userid'");
if($query=="0")
{
die("Sorry you dont have privileges that will allow you to do this");
}
else
{
$query=("insert into table values(
value1='$whatever_php_string',
value2='$some_other_string')");
}

I'm sorry i didn't have time to put in your variable names, but i think you should be able to do it yourself...
I also think that there is another way to do this, just cant think of it right now.

sansoft
New php-forum User
New php-forum User
Posts: 44
Joined: Fri May 07, 2004 2:16 am
Location: India
Contact:

abt insertion of different kind

Postby sansoft » Fri May 14, 2004 8:42 pm

hi,

i am using sessions in the login page....rt now,,,the thing is i am just introduced to it.......i have registered the variables......user_name and user_pass and on the basis of user_type as A or C i am sent to different pages.....
heres the code....on the basis of tht can u plz help me rt now.....means if i assign a session id to a particular user....only his details shud go down under!!!! plz help i am stuck.......



Code: Select all

<?include"../include/mysqlconnect.php";
$user_name=$HTTP_POST_VARS['username'];
$user_pass=$HTTP_POST_VARS['password'];
session_start();
//$uid=$user_id;
//$utype=$usr_type;
//session_register($un);
//session_register($utype);

if ($user_name!="" && $user_pass!="")
{
$sql="select user_name,user_id,user_type ,user_pass,user_type from mast_user where user_name='" .$user_name ."' and  user_pass ='" .$user_pass ."' ";
$result=mysql_query($sql,$conn);
$numrows=mysql_num_rows($result);

if ($numrows==1)
{
$row=mysql_fetch_object($result);
$sesuserid=$row["userid"];
$sestype=$row["usr_type"];

session_register('sesuserid');
session_register('sestype');




if($row->user_type=='A')
{
echo'<a href="masteruserform.php?' . session_id() . '">';
}


//else
//{

//$msg="invalid login";
//}

if($row->user_type=='C')
{
header('location: ../user/everydaytaskdetails.php?sessid='.session_id());
}
}

else
{
session_destroy();
$msg="invalid login";

}



}

sansoft
New php-forum User
New php-forum User
Posts: 44
Joined: Fri May 07, 2004 2:16 am
Location: India
Contact:

problem solved sing sessions

Postby sansoft » Sat May 15, 2004 7:18 pm

the problem is finally solved using sessions which i was just introduced a few hrs back......i read the entire topic and implemented it myself.......Really useful feature of PHP..............

the problems solved.............thank u everyone.......

:-D
Sansoft


Return to “PHP Scripts”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest