Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Forms for multiples users based on their user level

    Hi,

    I need help on how to do a form where many user can fill in the form but it based on the user level. In this form there are 3 users(STUDENT, ADMIN and LECTURER) used one form. First of all, Student need to fill in the project title, date and proposal supervisor . Then Lecturer need to gives comment and lastly Admin also need to reply to this form for validation.

    Where Student only can see the project title, date and proposal supervisor fields, Lecturer can see all the entered fields by the Student and lastly as Admin, he/she can view what had been entered by the Student and Lecturer

    Below is the form.php the codes that I have done so far:
    PHP Code:
    <?php
    //form.php
    include 'connect.php';

    /*if($_SESSION['profile'] == false)
    {
            echo 'Sorry, you have to be <a href="/forum/signin.php">signed in</a> to create a topic.';
    }
    else
    {    */
        
    if($_SERVER['REQUEST_METHOD'] != 'POST')
        {
            
    $sql "SELECT * from gs04";
            
            
    $result mysql_query($sql);
            
                if(!
    $result)
                    {
                        
    //the query failed, uh-oh :-(
                        
    echo 'Error while selecting from database. Please try again later.';
                    }
                    else
                    {
                        if(
    mysql_num_rows($result) == 0)
                        {
                            if(
    $_SESSION['profile'] == 'Student')
                            {
                                echo 
    '<form method="post" action="">';
                                echo 
    '<p>Thesis Title: <br> <textarea cols="50" rows="5" name="doc_type" wrap="hard"></textarea></p>';
                                echo 
    '<p>Propsal Date: <input type="text" id="datepicker" /></p>';
                                echo 
    '<p>Proposal Supervisor: <input type="text" name="prop_supervisor" /></p>';
                            }
                            if (
    $_SESSION['profile'] == 'Lecturer'){
                                echo 
    '<p>=Lecturer Comments: <input type="text" name="lecturer_comment" /></p>';
                            }
                            if (
    $_SESSION['profile'] == 'Admin'){
                                echo 
    '<p>=Admin Comments: <input type="text" name="dean_comment" /></p>
                                </form>'
    ;
                            }
                        }
                    }
                
            }
            else
            {
                
    $sql "INSERT INTO gs04(thesis_title, date, prop_supervisor, superisor_comment, dean_comment, user_id, s_reg)
                        VALUES('" 
    mysql_real_escape_string($_POST['thesis_title']) . "',
                                   NOW(),
                                   " 
    mysql_real_escape_string($_POST['prop_supervisor']) . ",
                                   " 
    mysql_real_escape_string($_POST['supervisor_comment']) . ",
                                   " 
    mysql_real_escape_string($_POST['dean_comment']) . ",
                                   " 
    $_SESSION['user_id'] . ",
                                   " 
    $_SESSION['s_reg'] . "
                                   )"
    ;
                                   
                
    $result mysql_query($sql);
                if(!
    $result)
                {
                        
    //something went wrong, display the error
                        
    echo 'An error occured while inserting your post. Please try again later.<br /><br />' mysql_error();
                        
    $sql "ROLLBACK;";
                        
    $result mysql_query($sql);
                }
                else
                {
                        
    $sql "COMMIT;";
                        
    $result mysql_query($sql);
                        
                        
    //after a lot of work, the query succeeded!
                        
    echo 'You have succesfully inserted your data.';
                }
            }
    ?>
    After I run this code I got this:
    PHP Code:
    NoticeUndefined indexprofile in C:xampphtdocstestadmingstry.php on line 28

    Notice
    Undefined indexprofile in C:xampphtdocstestadmingstry.php on line 35

    Notice
    Undefined indexprofile in C:xampphtdocstestadmingstry.php on line 38 
    Please help me... Thanks in advance!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You may change
    PHP Code:
    if($_SESSION['profile'] == 'Student'
    to
    PHP Code:
    if(isset($_SESSION['profile']) && $_SESSION['profile'] == 'Student'
    to avoid those warnings.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    hujan (03-25-2013)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    You may change
    PHP Code:
    if($_SESSION['profile'] == 'Student'
    to
    PHP Code:
    if(isset($_SESSION['profile']) && $_SESSION['profile'] == 'Student'
    to avoid those warnings.
    Thanks for the solution!

    Unfortunately, all the fields are not display . Can you help me on this?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    PHP Code:
    if(isset($_SESSION['profile'])){
        echo 
    '<form method="post" action="">';
        if(
    $_SESSION['profile'] == 'Student')
        {
            
            echo 
    '<p>Thesis Title: <br> <textarea cols="50" rows="5" name="doc_type" wrap="hard"></textarea></p>';
            echo 
    '<p>Propsal Date: <input type="text" id="datepicker" /></p>';
            echo 
    '<p>Proposal Supervisor: <input type="text" name="prop_supervisor" /></p>';
        }
        if (
    $_SESSION['profile'] == 'Lecturer'){
            echo 
    '<p>=Lecturer Comments: <input type="text" name="lecturer_comment" /></p>';
        }
        if (
    $_SESSION['profile'] == 'Admin'){
            echo 
    '<p>=Admin Comments: <input type="text" name="dean_comment" /></p>';
        
        }
        echo 
    '</form>';

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    hujan (03-25-2013)

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Try
    PHP Code:
    if(isset($_SESSION['profile'])){
        echo 
    '<form method="post" action="">';
        if(
    $_SESSION['profile'] == 'Student')
        {
            
            echo 
    '<p>Thesis Title: <br> <textarea cols="50" rows="5" name="doc_type" wrap="hard"></textarea></p>';
            echo 
    '<p>Propsal Date: <input type="text" id="datepicker" /></p>';
            echo 
    '<p>Proposal Supervisor: <input type="text" name="prop_supervisor" /></p>';
        }
        if (
    $_SESSION['profile'] == 'Lecturer'){
            echo 
    '<p>=Lecturer Comments: <input type="text" name="lecturer_comment" /></p>';
        }
        if (
    $_SESSION['profile'] == 'Admin'){
            echo 
    '<p>=Admin Comments: <input type="text" name="dean_comment" /></p>';
        
        }
        echo 
    '</form>';

    It still does not display anything . BTW below is the latest code:

    PHP Code:
    <?php

    include 'connect.php';

    /*if($_SESSION['profile'] == false)
    {
            echo 'Sorry, you have to be <a href="/forum/signin.php">signed in</a> to create a topic.';
    }
    else
    {    */
        
    if($_SERVER['REQUEST_METHOD'] != 'POST')
        {
            
    $sql "SELECT * from gs04";
            
            
    $result mysql_query($sql);
            
                if(!
    $result)
                    {
                        
    //the query failed, uh-oh :-(
                        
    echo 'Error while selecting from database. Please try again later.';
                    }
                    else
                    {
                        if(
    mysql_num_rows($result) == 0)
                        {
                            if(isset(
    $_SESSION['profile'])){
                            echo 
    '<form method="post" action="">';
                            if(
    $_SESSION['profile'] == 'Student')
                            {
                                
                                echo 
    '<p>Thesis Title: <br> <textarea cols="50" rows="5" name="doc_type" wrap="hard"></textarea></p>';
                                echo 
    '<p>Propsal Date: <input type="text" id="datepicker" /></p>';
                                echo 
    '<p>Proposal Supervisor: <input type="text" name="prop_supervisor" /></p>';
                            }
                            if (
    $_SESSION['profile'] == 'Lecturer'){
                                echo 
    '<p>=Lecturer Comments: <input type="text" name="lecturer_comment" /></p>';
                            }
                            if (
    $_SESSION['profile'] == 'Admin'){
                                echo 
    '<p>=Admin Comments: <input type="text" name="dean_comment" /></p>';
                            
                            }
                            echo 
    '</form>';
                        }  
                    }
                }
            }
        else
            {
                
    $sql "INSERT INTO gs04(thesis_title, date, prop_supervisor, superisor_comment, dean_comment, user_id, s_reg)
                        VALUES('" 
    mysql_real_escape_string($_POST['thesis_title']) . "',
                                   NOW(),
                                   " 
    mysql_real_escape_string($_POST['prop_supervisor']) . ",
                                   " 
    mysql_real_escape_string($_POST['supervisor_comment']) . ",
                                   " 
    mysql_real_escape_string($_POST['dean_comment']) . ",
                                   " 
    $_SESSION['user_id'] . ",
                                   " 
    $_SESSION['s_reg'] . "
                                   )"
    ;
                                   
                
    $result mysql_query($sql);
                if(!
    $result)
                {
                        
    //something went wrong, display the error
                        
    echo 'An error occured while inserting your post. Please try again later.<br /><br />' mysql_error();
                        
    $sql "ROLLBACK;";
                        
    $result mysql_query($sql);
                }
                else
                {
                        
    $sql "COMMIT;";
                        
    $result mysql_query($sql);
                        
                        
    //after a lot of work, the query succeeded!
                        
    echo 'You have succesfully inserted your data.';
                }
            }

    ?>

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    It still does not display anything
    What's you expected display?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    What's you expected display?
    1) Once Student sign in and open the form is should display Thesis title, Proposal date and Proposal supervisor

    2) For Lecturer; will should display all the data that had been entered by student and a comment field for Lecturer to fill in.

    3) For Admin, it should display all the entered data by the Student and Lecturer; and a comment field for Admin to fill in

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Are you sure that the variable $_SESSION['profile'] is set with some value?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    What do you mean? I don't get it *confused*

  • #10
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    1st line of php needs to be session_start();

    PHP Code:
    <?PHP
    session_start
    ();

    //blah blah
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #11
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    1st line of php needs to be session_start();

    PHP Code:
    <?PHP
    session_start
    ();

    //blah blah
    ?>
    I got:

    PHP Code:
    NoticeA session had already been started ignoring session_start() in C:xampphtdocstestadminconnect.php on line 2 
    When I added session_start();
    echo $_SESSION['profile'];
    . I got:

    PHP Code:
    NoticeUndefined indexprofile in C:xampphtdocstestadmingstry.php on line 3

    Notice
    A session had already been started ignoring session_start() in C:xampphtdocstestadminconnect.php on line 2 
    Last edited by hujan; 03-25-2013 at 09:04 PM.

  • #12
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    post your code your using to set $_SESSION['profile']
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #13
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    post your code your using to set $_SESSION['profile']
    still i got:

    PHP Code:
    NoticeUndefined indexprofile in C:xampphtdocstestadmingstry.php on line 3

    Notice
    A session had already been started ignoring session_start() in C:xampphtdocstestadminconnect.php on line 2 

  • #14
    New Coder
    Join Date
    Oct 2012
    Posts
    29
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    post your code your using to set $_SESSION['profile']
    still i got:

    PHP Code:
    NoticeUndefined indexprofile in C:xampphtdocstestadmingstry.php on line 3

    Notice
    A session had already been started ignoring session_start() in C:xampphtdocstestadminconnect.php on line 2 

  • #15
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    ok, so take that line back out and post the code your setting the variable with
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  
    Page 1 of 3 123 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •