1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

PHP Help

Discussion in 'BBS Hangout' started by Lil Pun, Apr 20, 2011.

  1. Kyakko

    Kyakko Contributing Member

    Joined:
    Aug 15, 2002
    Messages:
    2,161
    Likes Received:
    39
    Yea, it's annoying. I was going to fix this, but I've seem to lost the edit option for that post.
     
  2. Kyakko

    Kyakko Contributing Member

    Joined:
    Aug 15, 2002
    Messages:
    2,161
    Likes Received:
    39
    Lilpun,

    Upon research, the url is just an alias to the actually file, so file_exist will return false (unless you have a wrapper installed, most don't).

    Instead of "http://myapp.mydomain.com/documents/x.doc"

    It should look something like "/var/users/.... document/x.doc"

    if your docs are in the same root directory as your php file, use dirname(__FILE__) to get the directory name..

    i.e.

    $dcnXX= dirname(__FILE__) ."/documents/".$filename;
     
  3. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    I thought I noted the problem above. It is as if the code is say the if and elseif statements are false and doing the else because whatever is in position 4 gets open. So in my code listed last, PDF files open but doc and docx files do not.
     
  4. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    Yeap. I said that earlier. The location isn't a URL, but a PATH. :eek:

    Also, notice that the instruction "Location:" is for redirecting your browser to load whatever is in the location URL. My point with this is that you don't get a chance to troubleshoot. Don't do the "Location:" instruction until you know that the URL exists. Check it with a browser by writing out the URL you want to check, but don't send the browser to a different location.

    Do this (top-down method):

    get dcn location from string
    what is the dcn?
    check the dcn. add it to the string for dcncheck.
    write out the dcnstring
    does dcnstring exist?
    yes? write it out. allow someone to click it.
    no? write it out. do not allow someone to click it.

    Don't send the user somewhere before knowing that your code writes it out properly. Your "Location:" instruction tells the browser to GO, not to decide whether it can go or stay where it is (your script). :cool:
     
  5. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    Finally got it to work using the following:

    Code:
    < ? php $dcnCheck=$_GET['dcn' ];
    
    $dcnCheck2= $dcnCheck . ".doc";
    $dcnCheck3= $dcnCheck . ".docx";
    $dcnCheck4= $dcnCheck . ".pdf";
    
    echo "What we received on the GET: $dcn\n";
    echo "This is dcnCHECK2: $dcnCheck2\n";
    echo "This is dcnCHECK3: $dcnCheck3\n";
    echo "This is dcnCHECK4: $dcnCheck4\n";
    
    if (file_exists($dcnCheck2)) {
    header("Location:$dcnCheck2");
    }
    elseif (file_exists($dcnCheck3)) {
    header("Location:$dcnCheck3");
    
    } else {
    header("Location:$dcnCheck4");
    }
    
    ?>
    file_exists is looking for a file and not a URL so I made that change and it worked.

    Thanks again for all of your help, it is greatly appreciated.
     
  6. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
  7. Kyakko

    Kyakko Contributing Member

    Joined:
    Aug 15, 2002
    Messages:
    2,161
    Likes Received:
    39
    I'm guessing that won't work also. You can't write to the page before sending the header information. :)
     
  8. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021

    No, we've tested and it is working now.
     
  9. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021

    Yeah, I know. :) Thanks for your help though.
     
  10. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    OK, I have another PHP question. I currently have a web page where students can login and check their graduation information.

    Right now, they enter their ID on a login page and then their graduation information shows up if they are in the database. If not, they get a message saying so.

    What I want to add is a page before they enter their ID with a drop down menu of the terms they could be graduating. So for example they would go to the page and get a drop down menu that gave them the options of

    Summer 2011

    Fall 2011

    Spring 2012

    After they select one of these, their selection calls a specific table within the database. Say for example graduationSummer, graduationFall, graduationSpring for each one. Then they would enter their ID and get their information as before. I want to add this step so I can load more than one term worth of graduation data. It seems like something that would be easy to do if you had the know-how but I may be wrong.

    Any suggestions?

    Thanks!
     
  11. madmonkey37

    madmonkey37 Contributing Member

    Joined:
    Jun 20, 2003
    Messages:
    2,499
    Likes Received:
    52
    not sure if I completely understand what you want, but it seems like all you want is a simple drop down menu populated with the three terms? If thats the case then a simple html drop down menu using the select tags should suffice.
     
  12. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    But I also want the selection from the drop down menu to pull data from a specific table within a database.

    For example.

    1. You pick Summer 2011 as your graduation term from the drop down menu.

    2. When you put your ID in on the next page it looks for you in the graduationSummer table within the database and gives you the desired information.
     
  13. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    Make yourself another table in the MySQL database called "available_semesters" and give each record an ID that's unique. Then, write a script that loops through the available records and have that one ALWAYS available... OR:

    To make things even more interesting, gather unique "available_semester" entries from all possible entries with a separate query or SQL statement "search unique available_semesters from table enrollments" and loop through it when you write < option > tags in your < select > form.

    :cool: Don't HARD-CODE twice. Enter records ONCE. You'll never have to go back to "available_semesters" tables if you just get them dynamically. Make the latest record entry be the one that is selected by default in the drop-down options.

    For example, if I am student ABC123 in table "students", and I haven't been a student in semester code 2011_01, then I won't see that option available in the drop-down menu. If I didn't go to school in 2011, but I did in 2010, then my first choice would be 2010, and I wouldn't even see 2011 in my choices. ;) Good luck, man. Challenge yourself.
     
  14. madmonkey37

    madmonkey37 Contributing Member

    Joined:
    Jun 20, 2003
    Messages:
    2,499
    Likes Received:
    52
    Hmm, hard to help with out exactly seeing how the tables are made.

    Assuming the student ID is the primary key for each table, the simplest way would be to have the values of the drop down menu be the same as the tablename. So once you retrieve the term from the drop down menu, you can just populate an SQL statement with the table name and student ID.

    SELECT * FROM $tablename WHERE id = $studentid
     
  15. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    What do you need to see about the tables?
     
  16. Kyakko

    Kyakko Contributing Member

    Joined:
    Aug 15, 2002
    Messages:
    2,161
    Likes Received:
    39
    Not to be the PHP security police, but you should not let a user input define the table name. For security reasons, all the tables names used should be set in the code itself.

    For example:

    if ($dropdownTable =="A") $tablename="students";
    else $tablename="teachers";
     
  17. madmonkey37

    madmonkey37 Contributing Member

    Joined:
    Jun 20, 2003
    Messages:
    2,499
    Likes Received:
    52
    Does the posted solution work for you?

    I just assumed each graduation term already has its own table, and the primary key for each of those tables is the student ID. If thats the case then the solution should be pretty simple.
     
  18. SwoLy-D

    SwoLy-D Contributing Member

    Joined:
    Jul 20, 2001
    Messages:
    37,617
    Likes Received:
    1,448
    You also shouldn't HARD-CODE the table names from the options in the drop-down combo select in the form fields, either. Just don't HARD-CODE. Let the tables handle what the options are. :eek:
     
  19. madmonkey37

    madmonkey37 Contributing Member

    Joined:
    Jun 20, 2003
    Messages:
    2,499
    Likes Received:
    52
    Sounds like good advice. I have a pretty poor foundation in PHP and general programming practices. After learning the basics I jumped straight into using frameworks that takes care of a lot the security details. Not the most ideal way to learn how to program, but the fastest.
     
  20. Lil Pun

    Lil Pun Contributing Member

    Joined:
    Oct 6, 1999
    Messages:
    34,132
    Likes Received:
    1,021
    OK, maybe I am doing this all wrong. Instead of separating tables let's say I keep all the data in one table and I keep all of the current coding I have, right now the students enter their ID and then are given information.

    Would it be easier if the students received a different message based on their graduating term?

    Example:

    Fields and Example Data:

    ID First Name Last Name Term

    12345 Jane Doe SU2011
    12346 John Doe FA2011


    Based on the last field, it it possible to give students a different message.

    If term = SU2011

    We have received your graduation request for the Summer 2011 term. Thank you.

    Else

    We have received your graduation request for the Fall2011 term. Thank you.


    Would that be easier?
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now