SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What in the world do I do now?

    I have a database submission form, a sample of the form I am using I have posted below. I need to make it so it does the following:

    1. Upon submitting I need it to create a row in a table that has the username, and the locked status. So when the table is set to locked, it can not be submitted, until an admin changes that status to the unlocked position.

    2. I need it to email that form in html format to two email addresses.


    PHP Code:
    <?php
    $db_host 
    "localhost";
    $db_user "lefteh";
    $db_pwd "1234";
    $db_name "MyDB";
    mysql_connect($db_host$db_user$db_pwd);
    mysql_select_db($db_name);
    ?>
    <html>
    <head>
    <title>My first MySQL form submission</title>
    </head>
    <body>
    <?php
    if (!isset($_POST['submit'])) {
    ?>
    <form action="" method="post">
    Name: <input type="text" name="name"><br>
    Favorite Color: <input type="text" name="color"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php
    } else {
    $name $_POST['name'];
    $color $_POST['color'];
    mysql_query("INSERT INTO `colors` (name, favoriteColor) VALUES ('$name', '$color')");
    echo 
    "Success! Your favourite colour has been added!";
    }
    ?>
    </body>
    </html>

  2. #2
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any comments or suggestions would be great. Also links to any documentation that is similiar to what I need to dow would be a big help.

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wicked,
    1. Create a table called "locked".
    2. Create a field called UserID.
    3. Assign each user a unique ID. ( can be auto incremented )
    4.
    PHP Code:
    function LockForm$UserID ) {
      
    $query =  "Insert into locked set UserID = '" $UserID "'"// Create query  
      
    db_open(); // Open database
      
    mysql_query$query ); // Execute query
      
    if (mysql_errno()) { // Check for errors
            
    echo "Could not Lock Form<br />\n";
            echo 
    "Error Number : " .mysql_errno(). "\n";
            exit;
      }

    fuction IsLocked$UserID ) {
      
    $query "select * from locked where UserID = '" .$UserID"'"//Create query
      
    db_open(); // Open database
      
    $result mysql_query$query ); // Execute query
      
    if ( $result ) { // Check for results
        
    return True;
      } else {
        return 
    False;
      }

    There are two of your functions to get you started, I think this will give you a direction to head.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where does that code go?

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the first function to add the users Id to a table of users that are in a locked down status.
    Use the second function to determine if the user is locked down.

    Put that code into a file and call it form.fns, you have some more functioins you need to add such as Unlock($UserID)

    You do realize the db_open() function is one you should construct:
    PHP Code:
    function db_open() {
      
    $db_host "localhost";
      
    $db_user "lefteh";
      
    $db_pwd "1234";
      
    $db_name "MyDB";

      
    mysql_connect($db_host$db_user$db_pwd);
      if (
    mysql_errno()) { // Check for errors
        
    echo "Could not Connect to Database<br />\n";
        echo 
    "Error Number : " .mysql_errno(). "\n";
        exit;
      }
      
    mysql_select_db($db_name);
       if (
    mysql_errno()) { // Check for errors
         
    echo "Could not Open Database<br />\n";
         echo 
    "Error Number : " .mysql_errno(). "\n";
         exit;
      }

    Put that function into a file and name it something like "db.fns";

    Include this file on any page where you will be making data base calls.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  6. #6
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that go in a php string or?

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By php string I take it you mean <?php ?>...

    Yes, any code you want interpreted as php must be in the above.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  8. #8
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it matter where I place this, and does it lock upon pressing submit?

  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When the user submits the form you will need to send the data to a from handler page. After writing the data to the database and adding the user to the locked table you will need to return to the original submitted form page, which will be blank. Before displaying this form you will need to check if the user has made a submission. Do you have a function that displays the form with the user's submitted information? You will need one.
    When displaying the form use "edit for the value of the submit button, check if the user is in the locked table and if so disable the submit button.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  10. #10
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in there form itself the data is pulled and showed in the values, I'm still a little confused of the whole concept though.

  11. #11
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't you write the function that displays the form with values in it?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  12. #12
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I put the php in there to show what that value was

  13. #13
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you say that value I would take it you mean the values of all the fields in the form. How many fields are on this form? Do you have one function to display a blank form and one to display a filled in form?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  14. #14
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have two different pages, one that shows input forms, and what that shows the variables submitted. There is 400 input buttons.

  15. #15
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't get that piece of code working with my design. What If I made another column where my users were and checked the locked status in there.?

  16. #16
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good database design dictates that you should keep only the necessary data required to return valid result sets... In other words I dont know how many users you plan on having, or how many of them you plan on having in a locked down condition but I am willing to bet the # of locked down users will be small compared to the total number of users. Why store an unlocked condition for 10,000 people when only 100 need to be locked down?

    The only way to submit a form is with the submit button, check to see if your user is on the locked list and if so DISABLE the submit button.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  17. #17
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It needs to be for every user, there is 150 users.. The disabling the submit button is exactly what I need to do.. I just have no idea how to do it.

  18. #18
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
     <input type="submit" value="Edit" disabled="disabled" />
    This is basic HTML, perhaps this project is above your skill level.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  19. #19
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is above my skill level, which is why I came here for help. So here is what needs to be done to my understanding.

    If you press submit UPDATE authorize SET LockStatus ='LOCKED' WHERE ='$_SESSION['user_name'])'. Else - Select LockStatus from authorize is = to LOCKED show <input type="submit" value="Edit" disabled="disabled" /> Else If - Select LockStatus from authorize is not equal to LOCKED, then show <input type="submit" value="submit" name="submit">

    I think that is what needs to be done? If so how do I represent that in the code?

  20. #20
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, go back up this thread and look at the two functions I wrote for you.
    LockForm() writes the users ID to a table. Yes I understand you need to be able to lock all 150 of your users, but at any given time you will only have a few of these users locked. If you want to lock all of them out then you don't need to know if the member is on a locked out list!
    Look @ the second function IsLocked() does a lookup to see if the user is on a locked list and returns a True or False.

    My logic says
    1. User fills out form and submits data.
    2. When you store users values you add there name to the locked table using LockForm().
    3. User returns to form and you fill in with users data.
    4. When you get to the submit button you check to see if the user is in the locked table using the IsLocked() function.
    5. If IsLocked() returns True(1) you disable the submit button.
    6. if IsLocked() returns False(0) you do not disable the submit button.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  21. #21
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't need to lock all the users at once, and all the users will rarely be locked at the same time. It's just when they press the submit button will they need to be locked, and only then. So locking all the users at once will do me no good. So I need it to lock them solely on when they click the submit button, and then they will be unlocked by the admin in the admin section.

  22. #22
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get your point quite clearly, I am trying to get the point across that it is quicker to scan a table ( locked ) with 10 users who have submitted data and the admin has not released as compared to a table ( users ) with 150 users. Each user does not need a locked field in there record set, you simply need to record the locked users unique ID in a table. Much smaller data footprint say 10 records compared to 150 records.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  23. #23
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ohhh I understand now. I still don't have the slighest idea what you are telling me to do with the functions though.

  24. #24
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your form go to a form handler page? Do you do an Insert query to save your user's data? Save the data first and after checking for errors lock your user using the LockForm() function. You simply want to write your user's unique ID to this table so you can check later (using the IsLocked() ) to determine if the users name is in that table.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  25. #25
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I posted the exact form I am using in my original post. It is not going to a form handler page.


Bookmarks

Posting Permissions

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