User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,001 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,424 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1185 | Replies: 4
Reply
Join Date: Aug 2006
Posts: 7
Reputation: s s paul is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
s s paul s s paul is offline Offline
Newbie Poster

passing session

  #1  
Jul 1st, 2007
Hello I want to pass the database retrieved username after user logs on & hence to check login correctness I am using php & jsp
  1. <?php
  2. $conn= mysql_connect("localhost", "root", "");
  3. if(!$conn){
  4. exit("Error in SQL");
  5. }
  6. mysql_select_db("college", $conn);
  7. $val1=$_REQUEST['login1'];
  8. $val2=$_REQUEST['password1'];
  9.  
  10. $sql = "SELECT * FROM tlogin WHERE tid='$val1' AND tpasswd='$val2'";
  11. $rt = mysql_query($sql, $conn);
  12. $num = mysql_num_rows($rt);
  13.  
  14. if($num==0){
  15. print("<script language='javascript'>");
  16. print("window.location='index.html';");
  17. print("alert(\"Incorrect username or password...\")");
  18. print("</script>");
  19. }
  20. else
  21. {
  22.  
  23. mysql_select_db("college", $conn);
  24. $row= mysql_fetch_array($rt);
  25. $tname=$row['$tname'];
  26. $_POST['$tname'];
  27. URL=http://172.31.81.150/teacher.php?exvar='$tname';
  28. //$sql = "SELECT sname FROM register WHERE regno=$val1";
  29. //$rt=mysql_query($sql,$conn);
  30. //$a_row = mysql_fetch_array( $rt );
  31. //$sname=stripslashes($a_row['sname']);
  32. //echo urlencode($_GET['sname']);
  33.  
  34. //session_register("username");
  35.  
  36. //username = "$sname";
  37. //$_SESSION[$sname]="$sname";
  38. setcookie("auth", "1", 0, "/", "", 0);
  39. //print("<script language='javascript'>");
  40.  
  41. //print("window.location='teacher.php';");
  42. //print("</script>");
  43. }
  44. ?>
But am unable to transfer the usrname so that I can welcome him in next page
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: passing session

  #2  
Jul 1st, 2007
Last edited by iamthwee : Jul 1st, 2007 at 4:06 am.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Aug 2006
Posts: 7
Reputation: s s paul is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
s s paul s s paul is offline Offline
Newbie Poster

Re: passing session

  #3  
Jul 2nd, 2007
unable to find correct solution
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: passing session

  #4  
Jul 2nd, 2007
I guess a simple example would be...

pass.php

<a href="temp.php?var=hello">test</a>

temp.php

<?
echo $_GET['var'];
?>

Which should display the word hello, which is passed from pass.php (the first url) to the second url.

Straight from php man
http://ca3.php.net/variables.external
Last edited by iamthwee : Jul 2nd, 2007 at 3:32 pm.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Jul 2007
Posts: 3
Reputation: doubledub is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
doubledub doubledub is offline Offline
Newbie Poster

Re: passing session

  #5  
Jul 5th, 2007
Before you can use. set, unset, etc any session variables you must first
  1. <? session_start(); ?>
on each page using sessions.
This is required and no session vars can be used otherwise. Its good practice to have at the top of your pages so you don't forget it.

Assuming that your query is pulling the correct data, define the session variable without the dollar sign and with single quotes like:
  1. $_SESSION['sname'] = $sname;
.

Retrieving it to display on any other page is now as simple as
  1. echo $_SESSION['sname'];
or for use however.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC