saving a value to reuse it

Discussion in 'PHP' started by Shaimaa, Feb 2, 2010.

  1. #1
    <html>
    <head>
    <script language=javascript type='text/javascript'> 
    function showAdmin()
    {
    	if(document.getElementById){
    		document.getElementById('admin').style.visibility= 'visible';
    	}
    }
    function showManager()
    {
    	if(document.getElementById){
    		document.getElementById('manager').style.visibility= 'visible';
    	}
    }
    
    function showTester()
    {
    	if(document.getElementById){
    		document.getElementById('tester').style.visibility= 'visible';
    	}
    }
    function showDeveloper()
    {
    	if(document.getElementById){
    		document.getElementById('developer').style.visibility= 'visible';
    	}
    }
    
    </script>
    </head>
    <body>
    
    <div id="admin" style="visibility:hidden">
    <h1>Welcome to administration Page</h1>
    <table>
    <tr><td><a href="adduser.php">Add User</a></td></tr>
    <tr><td><a href="updateuser.php">Update User</a></td></tr>
    <tr><td><a href="deleteuser.php">Delete User</a></td></tr>
    <tr><td><a href="createproject.php">Create Project</a></td></tr>
    <tr><td><a href="assign_project_member.php">Assign members to project</a></td></tr>
    <tr><td><a href="update_profile.php">Update Profile</a></td></tr>
    </table>
    </div>
    
    <div id="manager" style="visibility:hidden">
    <table>
    <tr><td><a href="assign_project_member.php">Assign Project Member</a></td></tr>
    <tr><td><a href="list_bugs.php">Show List of Bugs</a></td></tr>
    <tr><td><a href="assign_bugs.php">Assign Bugs to the Developers</a></td></tr>
    <tr><td><a href="update_profile.php">Update Profile</a></td></tr>
    </table>
    </div>
    
    <div id="tester" style="visibility:hidden">
    <h1>Welcome to Back</h1>
    <table>
    <tr><td><a href="addbug.php">Add Bug for each Project</a></td></tr>
    <tr><td><a href="update_bug_status.php">Update Bug Status</a></td></tr>
    <tr><td><a href="update_profile.php">Update Profile</a></td></tr>
    </table>
    </div>
    
    <div id="developer" style="visibility:hidden">
    <h1>Welcome to Back</h1>
    <table>
    <tr><td><a href="update_bug_status.php">Update Bug Status</a></td></tr>
    <tr><td><a href="update_profile.php">Update Profile</a></td></tr>
    </table>
    </div>
    <?php
     /*...
        ... Some Code to get the value of UserID ...
        ...*/
    ?>
    </body>
    </html>
    
    PHP:
    I want to save the value of UserID to reuse it again and post it to each page in each of div(s) again which is going to a different pages. :chomp:

    By the way I did the following

    echo '<input type="hidden" value="'.$userID.'" name="userID">';
    
    PHP:
    and I don't know how to use and I don't know if this way is true of not?

    Is it possible and how to do that?

    Thank You in advance
     
    Shaimaa, Feb 2, 2010 IP
  2. systematical

    systematical Peon

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Two involve cookies and the third is using a PHP session. I suggest I pickup a PHP book as this is a very basic question.

    JavaScript Cookie:
    http://www.w3schools.com/JS/js_cookies.asp

    PHP Cookie:
    http://php.net/manual/en/function.setcookie.php

    PHP Session:
    http://php.net/manual/en/features.sessions.php

    I'll give you an example of a php cookie.

    
    setcookie('user_id', $the_user_id_here, time()+3600);
    
    Code (markup):
    You can access this cookie this way:
    
    $_COOKIE['user_id'];
    
    Code (markup):
     
    systematical, Feb 2, 2010 IP
  3. Shaimaa

    Shaimaa Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have something like:

    <table>
    	 <tr>
         <td><input type="checkbox" name="day[]" value="Saturday" />Satur</td>
    	 
         <td><input type="checkbox" name="day[]" value="Sunday" />Sun</td>
         
         <td><input type="checkbox" name="day[]" value="Monday" />Mon</td>
         
         <td><input type="checkbox" name="day[]" value="Tuesday" />Tues</td>
        
         <td><input type="checkbox" name="day[]" value="Wednesday" />Wednes</td>
         
         <td><input type="checkbox" name="day[]" value="Thursday" />Thurs</td>
         
         <td><input type="checkbox" name="day[]" value="Friday" />Fri</td>
    	 </tr>
    	 </table>
    PHP:
    and I want to save day[] in a session and reuse it again how can I do that?

    Thank you in advance
     
    Shaimaa, Feb 17, 2010 IP