Explain this code pls

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by balaji2u, Dec 12, 2008.

  1. balaji2u

    balaji2u New Member

    Messages:
    410
    Likes Received:
    2
    Trophy Points:
    0
    im trying to working on a template based document building script.i think this code will help me to get a input from the user such that he dont need to type the full document just the name,places of his choice must be selected and our script will generate the final document with his needed text in the placeholder like {name} {place} etc.

    the code is here.pls tell me for what this code exactly for? and of these two codes which will best suit my need?
    PHP:
    $Sdocbuild->db_Query"INSERT INTO `$tem_table` (`Template`) VALUES ('".$_POST['New_Template']."')" );
    second code is
    PHP:
        $SkaLinks->db_Query"UPDATE `$tem_table` SET `Template`='".$_POST['Letter_tem'][$value]."' WHERE `ID`='".$value."'" );
    thanks.
     
  2. compwhizii

    compwhizii Banned

    Messages:
    779
    Likes Received:
    0
    Trophy Points:
    0
    Those are queries to a MySQL database. From what I can gather those lines of code will not do anything to help you.
     
  3. freecrm

    freecrm New Member

    Messages:
    629
    Likes Received:
    0
    Trophy Points:
    0
    They are simple queries to a database, but they are returned from a (I think) a class or a function.

    you will probably find a bit of code above these a bit like..

    PHP:
    class Sdocbuild{
           function 
    something{
           }
    blah de blah
    }
    each class will contain a whole bunch of other variables and functions.

    the symbol "->" tells you that it is returning a value from a class or function.

    That said, it is also possible that these functions are in a different file; called at the beginning of the script.

    If this is a template, its going to make your life very tricky.

    As for the querys, the first one inserts a record with a value from a form (New_template) into a table defined by the variable $tem_table.

    The second query simply updates the same table. The column updated is "Template" and the value it is updating again comes from a form with a name "Letter_tem", providing the ID is like "value" (whatever value is).

    It is very difficult to tell without seeing what is in the function/class.
     
  4. vol7ron

    vol7ron New Member

    Messages:
    434
    Likes Received:
    0
    Trophy Points:
    0
    Close, nothing is necessarily returned. Its the equivalent of a "dot" operator in other Object Oriented langauges. So it is used to return a value or run a method. In this case it's running a subroutine to insert/update the table.

    Right. The first one inserts your template from the form as a record into the 'Template' field of your table. The second updates an existing template in the table.

    It might be better to include a link to your form and tell us what you want to happen.
     
  5. xcaliberse

    xcaliberse New Member

    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    Seems like a PHP/ MySQL script. I think what u need for this to happen is a HTML post code.
     
  6. balaji2u

    balaji2u New Member

    Messages:
    410
    Likes Received:
    2
    Trophy Points:
    0
    I want to have a text field that shows text like

    and now below this text box there are 4 drop down boxes one is {name} ,and for {place} and for {degree} and for {destination}
    all these drop down boxes have multiple values for example
    {name} list box contains options like vol7ron,corey,jackson etc
    now if he selects the name vol7ron then the next page(i.e page that comes after clicking submit button) must show the replaced texts and now it will become a easily made document.
    hope this is sufficient if you want to know more details pls dont hesitate to ask me.
     
  7. exghost

    exghost New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    you can use cookies to store data...and it will appear in the next page too..

    <?php
    session_start();
    setcookie ( 'name', 'vol7ron', time() + 1209600 );
    ?>

    and on the next page you can get it by using $_COOKIE['name'] like this

    <?php
    session_start();
    echo "Hi my name is".$_COOKIE['name'].", im living....";
    ?>
     
    Last edited: Dec 14, 2008
  8. xPlozion

    xPlozion New Member

    Messages:
    868
    Likes Received:
    1
    Trophy Points:
    0
    you don't need `session_start()` to use cookies. session_start is only if you are going to be using `$_SESSION`'s instead. you would set sessions like `$_SESSION['name'] = 'vol7ron';`. there's no expiration time since they expire when you close your browser.
     
  9. gptsven

    gptsven New Member

    Messages:
    253
    Likes Received:
    5
    Trophy Points:
    0
    you do need sessions when using cookies to automatically login a user -.-
     
  10. gptsven

    gptsven New Member

    Messages:
    253
    Likes Received:
    5
    Trophy Points:
    0
    You are the one who is ignorant.

    cookies are mainly used to auto-login users on forums/websites.

    and Im saying
    you need a session to log in, using the data from your cookie (autologin)

    "mister I argument everything and im always right"
    whats your argument for this line?

    firstly I'm not ILL-formed
    secondly,I didnt tell you you are wrong you idiot I only stated that you DO need sessions if you want users to be able to login automatically, dumb****, learn to read.

    Its nice to include a lot of arguments and sources in your post. for those who are still learning. I however do not need to learn anything anymore PHP-wise. I'm not saying I know everything, but I know how to use php.net to find and implement the functions I need. you did not enlighten me with your post. I know what sessions are, I know what cookies are. I KNOW OK? I'm not some retarded kid who just started doing php and is trying to bash you ok?


    so my advice for you is
    stay calm, and dont feel offended. cause that was never my intention.
    I really hope your reply on this post is going to be somewhat less childish
     
    Last edited: Dec 14, 2008
  11. vol7ron

    vol7ron New Member

    Messages:
    434
    Likes Received:
    0
    Trophy Points:
    0
    balaji2u,

    I'm just checking back now that it's after hours in my office. I'm not sure what's going on above, but there are several ways to accomplish what you're trying to do. They include:

    1) Cookies (as mentioned above)
    2) QueryString (recommended)
    3) Database/FileSystem Interaction (recommended if storing the data)

    Cookies are not necessarily needed here if you're trying to use a form to compose a document. The truth is this can all be done dynamically on the same page in Javascript using either input boxes, or changing the innerHTML of elements.

    If you're trying to store the user information for safe keeping, then you'll need something like the script in your original post. They store/update data in your database, all you need is a SELECT query to retrieve it.

    If the data is not something you want to save and there's not a lot of it, just use the QueryString. That is, your URL will be something like http://www.domainlagoon.com/assuran...ol7ron&place=DC&degree=BS&destination=so rich
    You can achieve this by setting your form's method to get (ie <form method="get"></form>)

    Then when you get to the next page, you'd parse the QueryString and be able to retrieve everything and fill it in the document you're making. However, if a user doesn't need to log in or anything, you can just prepare this document dynamically on the same page and not even use a submit button, or a form that goes to another page - again, this is achieved by using the DOM object's innerHTML property.
     
    Last edited: Dec 15, 2008

Share This Page