forms - Confused with php sessions for a user? -


in login.php store username , user id in sessions. after login user selects page , once lead page, can select lecturer name needs name, not other's lecturer. know lecturer name selected needs stored in session. afterwards, have match either user id or username control user can see. problem how match these sessions login.php , `lecturer.php. should create separate file sessions?

login.php

<?php   require ('connect.php');    $username = $_post['username'];   $password = $_post['password'];     if (isset($_post['submit'])) {     if ($username && $password) {        $check = mysql_query("select * users username='".$username."' , password= '".$password."'");        $rows = mysql_num_rows($check);       if(mysql_num_rows($check) != 0){        session_start();       $run_login =mysql_fetch_array($check);       $uid = $run_login['id'];       $_session['uid'] = $_post['uid'];       $_session['username']=$_post['username'];       header("location:../../statistics/home.php");      }     else{       die("could not find username or password.");    }  }   else {      echo "please fill fields.";  } } ?> 

lecturer.php

 <?php      include 'connect.php';     $year = mysql_real_escape_string($_post['year']);    $lecturer = mysql_real_escape_string($_post['lecturer']); // don't forget handle sql injections ...    $years     = array(         2005,         2006,         2007    );    $lecturers = array(         'dimopoulos',         'lagkas',         'kehagias',         'chrysochoou'    );   if(isset($_post['submit'])){          if (in_array($lecturer, $lecturers) && in_array($year, $years)) {                   $sql = "select unit_name,a1,a2,a3,l1,l2,l3,l4,l5,l6,l7,lavg,r1,r2,u1,u2,u3 $lecturer year=$year";              $result = mysql_query($sql);         }          else {             echo "no data found";         }    }   else{       echo "please select";   }    ?>  <html>  <head>     <link rel="stylesheet" type="text/css" href="../../statistics/style.css">  </head>  <body>    <div id="container">    <table id="table" width="900" border="1" cellspacing="1">    <tr>     <td>unit name</td>     <td>a1 </td>     <td>a2 </td>     <td>a3 </td>     <td>l1 </td>     <td>l2 </td>     <td>l3 </td>     <td>l4 </td>     <td>l5 </td>     <td>l6 </td>     <td>l7 </td>     <td>lavg </td>     <td>r1 </td>     <td>r2 </td>     <td>u1 </td>     <td>u2 </td>     <td>u3 </td>      </tr>     <?php        while($unit=mysql_fetch_assoc($result)){         echo "<tr>";         echo "<td>".$unit['unit_name']."</td>";         echo "<td>".$unit['a1']."</td>";         echo "<td>".$unit['a2']."</td>";         echo "<td>".$unit['a3']."</td>";         echo "<td>".$unit['l1']."</td>";         echo "<td>".$unit['l2']."</td>";         echo "<td>".$unit['l3']."</td>";         echo "<td>".$unit['l4']."</td>";         echo "<td>".$unit['l5']."</td>";         echo "<td>".$unit['l6']."</td>";         echo "<td>".$unit['l7']."</td>";         echo "<td>".$unit['lavg']."</td>";         echo "<td>".$unit['r1']."</td>";         echo "<td>".$unit['r2']."</td>";         echo "<td>".$unit['u1']."</td>";         echo "<td>".$unit['u2']."</td>";         echo "<td>".$unit['u3']."</td>";         echo "</tr>";         } ?>   </table>   </div>   </body>   </html>        lecturerform.php       <form name="myform" action="lecturer.php" method="post" > <b>lecturers:<b/> <select name="lecturer">   <option value="choose">please select..</option> <?php     $sql=mysql_query("select lec_name lecturer");      while($row=mysql_fetch_array($sql)){          echo "<option value='".$row['lec_name']."'>".$row['lec_name']."</option>";     }     ?>  </select><br/><br/>  <b>year:<b/> <select name="year">  <option value="choose">please select..</option> <option value="2005">2005</option>  <option value="2006">2006</option> <option value="2007">2007</option></select><br/><br/>   <br/> <input type="submit" name="submit" value="submit"> <input type="reset" name="reset" value="clear">  </form> 

put session_start() begin of lecturer.php page.

note:
have bad var name in login.php set $_session['uid']:

$uid = $run_login['id']; $_session['uid'] = $uid; // not $_post['uid']; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -